Equivalent of and.callThrough() in jest-preset-angular

14.2k Views Asked by At

Reading through this link i got to know that the equivalent of

and.callFake is mockImplementation and

and.returnValue is mockReturnValue.

Similarly is there an equivalent of and.callThrough() in jest-preset-angular?

2

There are 2 best solutions below

1
On

This question may be really old, but tripped me up recently.

Jest, by default, will call the underlying function in a similar manner to .and.callThrough().

This is the opposite behaviour of Jasmine, which blocks the call to the underlying function unless .and.callThrough() is specified.

To block the underlying call in Jest, call the mockImplementation() function.

1
On

Most of these Jasmine2-related methods are not available anymore. See the Jest documentation for more information on e. g. how to call through spied methods.


Outdated Answer

Jest by default will use Jasmine2 as test runner, and therefore you can use most (if not all) Jasmine methods.

All of the ones you requested are in Jest available, and.callFake, as well as and.returnValue and and.callThrough.