O'Reilly logo

Jasmine Cookbook by Munish Sethi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required