I am new and I want to mock a function that returns a Promise<boolean>.
I did this:
service.changeBookingAsync = jest.fn().mockReturnValue(boolean);
but I got this error :
error TS2693: 'boolean' only refers to a type, but is being used as a value here.
If you want to mock a Promise you have to use this:
jest.fn().mockImplementation(() => Promise.resolve(value));
Agree with @Max answer
Syntactic sugar function will be this way :
jest.fn().mockResolvedValue(value);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With