The code we want to test often requires objects that are not of interest during the test – things that are tangential to the code we want to test. Whether it's database access code, making HTTP requests or simply a suite of functions or service calls that do some calculations or processing, this tangential code is important but maybe not for the test currently being written. In this scenario, mock objects and functions can be used in place of the real objects or functions. And with Jasmine, mock objects and functions are built in using Spies – functions that can be used to replace other functions, monitoring how many times it was called, with what arguments, are more.
In this episode, you'll learn the basics of using Jasmine spies to replace functions that you don't necessarily want to execute during your tests. You'll see how to assert that these spies were called, how to check arguments, and more.