What is a test spy?
A test spy is a function that records arguments and thrown exceptions (if any) for all its calls.
Creating a spy as an anonymous function
The spy won’t do anything except record information about its calls. A common use case for this type of spy is testing how a function handles a callback:
const spy =
true if the spy was called at least once.
true if the spy was not called.
The number of recorded calls.
Array of arguments received, spy.args is an array of arguments received in the first call.
spy.calledWith(arg1[, arg2[, ...]])
true if spy was called at least once with the provided arguments. Can be used for partial matching, only provided arguments are checked against the actual arguments.