class-fixtures-factory
class-fixtures-factory copied to clipboard
Support for async fixtures
I'm trying to return a fixture where the outcome is the result of a async function, but I'm not getting any success. Is that possible or not yet?
You mean using @Fixture( () => Promise )
? IIRC that's not supported. Can you show your use case please?
Thanks for the prompt response @CyriacBr. The case is the following one:
@Fixture(() => hashPassword(faker.random.words()))
public password: string;
The function hashPassword uses a library called argon which generates cyphers only using async methods. I can use it like this:
const fakeUsers = fixture
.make(User)
.with({
password: await hashPassword(faker.random.alphaNumeric(6)),
})
But I can't define a fixture using it. It doesn't throw me a linter error, but on the execution fails.
I'll see if this is easily fixable.