January 2018
Beginner
658 pages
13h 10m
English
Now, checking if a spy was called or not called is great, but we can get even more detail out of our assertions. For example, what if I call the spy with the name Andrew and the age 25:
it('should call the spy correctly', () => { var spy = expect.createSpy(); spy('Andrew', 25); expect(spy).toHaveBeenCalled(); });
Now, we want to verify if the spy was not just called but was called with these arguments? Well, luckily, we have an assertion for that too. Instead of toHaveBeenCalled, we can call toHaveBeenCalledWith, and this lets us pass in some arguments and verify the spy was indeed called with those arguments.
As shown in the following code, we'll assert that my spy was called with Andrew and the number ...
Read now
Unlock full access