Mock functions, also known as spies, are special functions that allow us to track how a particular function is called by external code.
By using mock functions, we can know the following:
- The number of calls it received.
- Argument values used on each invocation.
- The “context” or this value on each invocation.
- How the function exited and what values were produced.
- We can also provide an implementation to override the original function behavior. And we can describe specific return values to suit our tests.