The number of recorded calls.
true if the spy was called at least once
true if spy was called exactly once
true if the spy was called exactly thrice
true if the spy was called exactly twice
Array of exception objects thrown, spy.exceptions[0] is the exception thrown by the first call. If the call did not throw an error, the value at the call’s location in .exceptions will be undefined.
The first call
The last call
true if the spy was not called
Array of return values, spy.returnValues[0] is the return value of the first call. If the call did not explicitly return a value, the value at the call’s location in .returnValues will be undefined.
The second call
The third call
Array of this objects, spy.thisValues[0] is the this object for the first call.
Returns true if the spy was always called with @param obj as this.
Returns true if spy was always called with the provided arguments (and possibly others).
Returns true if spy was always called with the exact provided arguments.
Returns true if spy was always called with matching arguments (and possibly others). This behaves the same as spy.alwaysCalledWith(sinon.match(arg1), sinon.match(arg2), ...).
Returns true if spy always returned the provided value.
Returns true if spy always threw an exception.
Returns true if spy always threw an exception of the provided type.
Returns true if spy always threw the provided exception object.
Like yield, but with an explicit argument number specifying which callback to call. Useful if a function is called with more than one callback, and simply calling the first callback is not desired.
Like callArg, but with arguments.
Returns true if the spy was called after @param anotherSpy
Returns true if the spy was called before @param anotherSpy
Returns true if spy was called after @param anotherSpy, and no spy calls occurred between @param anotherSpy and spy.
Returns true if spy was called before @param anotherSpy, and no spy calls occurred between spy and @param anotherSpy.
Returns true if the spy was called at least once with @param obj as this. calledOn also accepts a matcher spyCall.calledOn(sinon.match(fn)) (see matchers).
Returns true if spy was called at exactly once with the provided arguments.
Returns true if spy was called at least once with the provided arguments. Can be used for partial matching, Sinon only checks the provided arguments against actual arguments, so a call that received the provided arguments (in the same spots) and possibly others as well will return true.
Returns true if spy was called at least once with the provided arguments and no others.
Returns true if spy was called with matching arguments (and possibly others). This behaves the same as spy.calledWith(sinon.match(arg1), sinon.match(arg2), ...).
Returns true if spy/stub was called the new operator. Beware that this is inferred based on the value of the this object and the spy function’s prototype, so it may give false positives if you actively return the right kind of object.
Returns the nth call. Accessing individual calls helps with more detailed behavior verification when the spy is called more than once.
Zero based index of the spy call.
Returns an Array of all calls recorded by the spy.
Invoke callbacks passed to the stub with the given arguments. If the stub was never called with a function argument, yield throws an error. Returns an Array with all callbacks return values in the order they were called, if no error is thrown.
Set the displayName of the spy or stub.
Returns true if the spy/stub was never called with the provided arguments.
Returns true if the spy/stub was never called with matching arguments. This behaves the same as spy.neverCalledWith(sinon.match(arg1), sinon.match(arg2), ...).
Returns true if call did not receive provided arguments.
Returns true if call did not receive matching arguments. This behaves the same as spyCall.notCalledWith(sinon.match(arg1), sinon.match(arg2), ...).
Returns the passed format string with the following replacements performed:
Resets the state of a spy.
Replaces the spy with the original method. Only available if the spy replaced an existing method.
Returns true if spy returned the provided value at least once. Uses deep comparison for objects and arrays. Use spy.returned(sinon.match.same(obj)) for strict comparison (see matchers).
Returns true if spy threw an exception at least once.
Returns true if spy threw an exception of the provided type at least once.
Returns true if spy threw the provided exception object at least once.
Creates a spy that only records calls when the received arguments match those passed to withArgs. This is useful to be more expressive in your assertions, where you can access the spy with the same call.
Expected args
Holds a reference to the original method/function this stub has wrapped.
Invoke callbacks passed to the stub with the given arguments. If the stub was never called with a function argument, yield throws an error. Returns an Array with all callbacks return values in the order they were called, if no error is thrown. Also aliased as invokeCallback.
Invokes callbacks passed as a property of an object to the stub. Like yield, yieldTo grabs the first matching argument, finds the callback and calls it with the (optional) arguments.
Array of arguments received, spy.args[0] is an array of arguments received in the first call.