class-fixtures-factory icon indicating copy to clipboard operation
class-fixtures-factory copied to clipboard

Support for async fixtures

Open jfantunes opened this issue 4 years ago • 3 comments

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?

jfantunes avatar Jan 23 '21 21:01 jfantunes

You mean using @Fixture( () => Promise ) ? IIRC that's not supported. Can you show your use case please?

CyriacBr avatar Jan 24 '21 10:01 CyriacBr

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.

jfantunes avatar Jan 24 '21 11:01 jfantunes

I'll see if this is easily fixable.

CyriacBr avatar Jan 31 '21 15:01 CyriacBr