Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jest - mockReturnValue : Promise<boolean>

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.

like image 828
Sandro Rey Avatar asked Dec 17 '19 09:12

Sandro Rey


2 Answers

If you want to mock a Promise you have to use this:

jest.fn().mockImplementation(() => Promise.resolve(value));
like image 119
Max Avatar answered Sep 28 '22 14:09

Max


Agree with @Max answer

Syntactic sugar function will be this way :

jest.fn().mockResolvedValue(value);
like image 23
Sanket Phansekar Avatar answered Sep 28 '22 16:09

Sanket Phansekar