18

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?

radio_head
  • 1,306
  • 4
  • 13
  • 28

2 Answers2

30

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.

blorkfish
  • 21,800
  • 4
  • 33
  • 24
  • Does that mean that, wherever we used `.and.callThrough()` before, we can remove it and it calls the actual function? – dave0688 Nov 03 '22 at 13:29
-3

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.

wtho
  • 500
  • 5
  • 14
  • Since Jest 27 this seems to be not true anymore as deduced from here: https://githubmemory.com/repo/nrwl/nx/issues/6063 – jlang Oct 12 '21 at 12:52