Himanshu
Himanshu

Reputation: 2361

What is difference between method `toHaveBeenCalled()` and `andCalledThrough()`

While using the Jasmine Spies, how different is andCalledThrough() method from toHaveBeenCalled, does it actually run the original method completely? Any ideal scenarios when I should use it?

Upvotes: 0

Views: 516

Answers (1)

Yaron Schwimmer
Yaron Schwimmer

Reputation: 5357

These are two different steps in spying on a function.

When you declare a spy on a function, before the function is called, you can attach some instructions to what should be done when the function is called. and.callThrough() means that the actual implementation will be used. Other options are and.callFake() and and.returnValue(), which allow you to mock a response and not use the actual implementation.

After the function you spied on was called, you can verify it was called using expect and toHaveBeenCalled and its variations.

Please refer to the documentation.

Upvotes: 2

Related Questions