To create a spy, we'll call a function expect.createSpy inside the it callback function:
it('should call the spy correctly', () => {
expect.createSpy();
});
The createSpy is going to return a function, and that is the function that we'll swap out for the real one, which means we do want to store that in a variable. I'll create a variable called spy, setting it equal to the returned result:
it('should call the spy correctly', () => {
var spy = expect.createSpy();
});
And now we would inject spy into our code, whether it's app.js or some other function, and we would wait for it to get called. We can call it directly just like this:
it('should call the spy correctly', () => {
var spy = expect.createSpy();
spy();
});