Chapter 5. Jasmine Spies

A test double is a pattern on unit testing. It replaces a test dependent component with an equivalent implementation that is specific to the test scenario. These implementations are called doubles because although their behavior might be specific to the test, they act like, and have the same API as, the object they impersonate.

Spies are Jasmine's solution to test doubles. At its core, a Jasmine spy is a special type of function that records all interactions that happen with it. Therefore, they are very useful when a returned value or change in an object's state can't be used to determine whether a test expectation was a success. In other words, Jasmine spies are perfect when a test success can only be determined by behavior ...

Get Jasmine JavaScript Testing - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.