Spy Strategies
Learn how to use a custom spy strategy to help set up spies.
We'll cover the following
When we set up a spy in Jasmine, it can respond to method calls in a number of ways. The default behavior is to use the stub
method, which will do nothing. We also have a few other options available:
-
We can use
callFake
to provide a callback that will be fired instead of the real method. -
We can use
callThrough
to pass the method call on to the original object that we are spying on. -
We can specify a value to be returned using the
returnValue
orreturnValues
method. -
We can use the
throwError
to throw an error if the method is called. We could use this if we want to make certain that a specific method on the spy is never called.
Get hands-on with 1200+ tech skills courses.