Writing Jasmine tests using the spyOn() method and special matchers for spies

In Jasmine, mocks are referred to as spies. Spies are used to mock a function/object method. A spy can stub any function and tracks calls and all its arguments. Jasmine provides a rich set of functions and properties to enable mocking. There are special matchers to interact with spies that are, toHaveBeenCalled and toHaveBeenCalledWith. In this recipe, you will learn how to mock a function using Jasmine's spyOn() function and special matchers.

To write the Jasmine tests using spies, let's assume that you are developing an application for <ABC> company, which provides solutions for the health care industry. Currently, there is a need to design a component that can get ...

Get Jasmine Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.