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.
Specify the minimum amount of calls expected.
Specify the maximum amount of calls expected.
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.
Causes the original method wrapped into the stub to be called when none of the conditional stubs are matched.
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.
Causes the stub to call the argument at the provided index as a callback function. stub.callsArg(0); causes the stub to call the first argument as a callback. If the argument at the provided index is not available or is not a function, a TypeError will be thrown.
Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed. In Node environment the callback is deferred with process.nextTick. In a browser the callback is deferred with setTimeout(callback, 0).
Like stub.callsArg(index); but with an additional parameter to pass the this context.
Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed. In Node environment the callback is deferred with process.nextTick. In a browser the callback is deferred with setTimeout(callback, 0).
Like above but with an additional parameter to pass the this context.
Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed. In Node environment the callback is deferred with process.nextTick. In a browser the callback is deferred with setTimeout(callback, 0).
Like callsArg, but with arguments to pass to the callback.
Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed. In Node environment the callback is deferred with process.nextTick. In a browser the callback is deferred with setTimeout(callback, 0).
Makes the stub call the provided @param func when invoked.
Expect the method to be called exactly @param n times.
Replaces a new getter for this stub.
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.
Expect the method to never be called.
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), ...).
Defines the behavior of the stub on the @param n call. Useful for testing sequential interactions. There are methods onFirstCall, onSecondCall,onThirdCall to make stub definitions read more naturally. onCall can be combined with all of the behavior defining methods in this section. In particular, it can be used together with withArgs.
Alias for stub.onCall(0);
Alias for stub.onCall(1);
Alias for stub.onCall(2);
Expect the method to be called exactly once.
Returns the passed format string with the following replacements performed:
Causes the stub to return a Promise which rejects with an exception (Error). When constructing the Promise, sinon uses the Promise.reject method. You are responsible for providing a polyfill in environments which do not provide Promise. The Promise library can be overwritten using the usingPromise method. Since sinon@2.0.0
Causes the stub to return a Promise which rejects with an exception of the provided type. Since sinon@2.0.0
Causes the stub to return a Promise which rejects with the provided exception object. Since sinon@2.0.0
Resets both behaviour and history of the stub. This is equivalent to calling both stub.resetBehavior() and stub.resetHistory() Updated in sinon@2.0.0 Since sinon@5.0.0 As a convenience, you can apply stub.reset() to all stubs using sinon.reset()
Resets the stub’s behaviour to the default behaviour You can reset behaviour of all stubs using sinon.resetBehavior()
Resets the state of a spy.
Causes the stub to return a Promise which resolves to the provided value. When constructing the Promise, sinon uses the Promise.resolve method. You are responsible for providing a polyfill in environments which do not provide Promise. The Promise library can be overwritten using the usingPromise method. Since sinon@2.0.0
Causes the stub to return a Promise which resolves to the argument at the provided index. stub.resolvesArg(0); causes the stub to return a Promise which resolves to the first argument. If the argument at the provided index is not available, a TypeError will be thrown.
Causes the stub to return a Promise which resolves to its this value.
Restores all mocked methods.
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).
Makes the stub return the provided @param obj value.
Causes the stub to return the argument at the provided @param index. stub.returnsArg(0); causes the stub to return the first argument. If the argument at the provided index is not available, prior to sinon@6.1.2, an undefined value will be returned; starting from sinon@6.1.2, a TypeError will be thrown.
Causes the stub to return its this value. Useful for stubbing jQuery-style fluent APIs.
Defines a new setter for this stub.
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.
Expect the method to be called exactly thrice.
Causes the stub to throw the argument at the provided index. stub.throwsArg(0); causes the stub to throw the first argument as the exception. If the argument at the provided index is not available, a TypeError will be thrown. Since sinon@2.3.0
Expect the method to be called exactly twice.
Causes the stub to return promises using a specific Promise library instead of the global one when using stub.rejects or stub.resolves. Returns the stub to allow chaining.
Defines a new value for this stub.
Verifies all expectations on the mock. If any expectation is not satisfied, an exception is thrown. Also restores the mocked methods.
Expect the method to be called with the provided arguments and possibly others. An expectation instance only holds onto a single set of arguments specified with withArgs. Subsequent calls will overwrite the previously-specified set of arguments (even if they are different), so it is generally not intended that this method be invoked more than once per test case.
Expect the method to be called with the provided arguments and no others. An expectation instance only holds onto a single set of arguments specified with withExactArgs. Subsequent calls will overwrite the previously-specified set of arguments (even if they are different), so it is generally not intended that this method be invoked more than once per test case.
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.
Similar to callsArg. Causes the stub to call the first callback it receives with the provided arguments (if any). If a method accepts more than one callback, you need to use callsArg to have the stub invoke other callbacks than the first one.
Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed. In Node environment the callback is deferred with process.nextTick. In a browser the callback is deferred with setTimeout(callback, 0).
Like above but with an additional parameter to pass the this context.
Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed. In Node environment the callback is deferred with process.nextTick. In a browser the callback is deferred with setTimeout(callback, 0).
Causes the spy to invoke a callback passed as a property of an object to the spy. Like yields, yieldsTo grabs the first matching argument, finds the callback and calls it with the (optional) arguments.
Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed. In Node environment the callback is deferred with process.nextTick. In a browser the callback is deferred with setTimeout(callback, 0).
Like above but with an additional parameter to pass the this context.
Same as their corresponding non-Async counterparts, but with callback being deferred at called after all instructions in the current call stack are processed. In Node environment the callback is deferred with process.nextTick. In a browser the callback is deferred with setTimeout(callback, 0).
Array of arguments received, spy.args[0] is an array of arguments received in the first call.