Book Image

Jasmine JavaScript Testing Update

By : Paulo Vitor Zacharias Ragonha
Book Image

Jasmine JavaScript Testing Update

By: Paulo Vitor Zacharias Ragonha

Overview of this book

Table of Contents (15 chapters)

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 checking.