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

2

20

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?

Fairminded answered 7/1, 2018 at 14:0 Comment(0)
A
31

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.

Ayeaye answered 19/10, 2020 at 12:19 Comment(1)
Does that mean that, wherever we used .and.callThrough() before, we can remove it and it calls the actual function?Sachasachem
H
-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.

Hairpin answered 19/9, 2019 at 16:27 Comment(1)
Since Jest 27 this seems to be not true anymore as deduced from here: githubmemory.com/repo/nrwl/nx/issues/6063Leeann

© 2022 - 2024 — McMap. All rights reserved.