Sinon API Manual
Guide
Section
Method
- var mock = sinon.mock(obj);
- "var expectation = mock.expects(""method"");"
- mock.restore();
- mock.verify();
- mock.usingPromise(promiseLibrary);
- var expectation = sinon.expectation.create([methodName]);
- var expectation = sinon.mock([methodName]);
- expectation.atLeast(number);
- expectation.atMost(number);
- expectation.never();
- expectation.once();
- expectation.twice();
- expectation.thrice();
- expectation.exactly(number);
- expectation.withArgs(arg1, arg2, ...);
- expectation.withExactArgs(arg1, arg2, ...);
- expectation.on(obj);
- expectation.verify();
- var stub = sinon.stub();
- "var stub = sinon.stub(object, ""method"");"
- "var stub = sinon.stub(object, ""method"", func);"
- var stub = sinon.stub(obj);
- stub.withArgs(arg1[, arg2, ...]);
- stub.onCall(n); Added in v1.8
- stub.onFirstCall();
- stub.onSecondCall();
- stub.onThirdCall();
- stub.reset();
- stub.resetBehavior();
- stub.resetHistory();
- stub.callsFake(fakeFunction);
- stub.returns(obj);
- stub.returnsArg(index);
- stub.returnsThis();
- stub.resolves(value);
- stub.resolvesArg(index);
- stub.throws();
- "stub.throws(""name""[, ""optional message""]);"
- stub.throws(obj);
- stub.throws(function() { return new Error(); });
- stub.throwsArg(index);
- stub.rejects();
- "stub.rejects(""TypeError"");"
- stub.rejects(value);
- stub.callsArg(index);
- stub.callThrough();
- stub.callThroughWithNew();
- stub.callsArgOn(index, context);
- stub.callsArgWith(index, arg1, arg2, ...);
- stub.callsArgOnWith(index, context, arg1, arg2, ...);
- stub.usingPromise(promiseLibrary);
- stub.yields([arg1, arg2, ...])
- stub.yieldsRight([arg1, arg2, ...])
- stub.yieldsOn(context, [arg1, arg2, ...])
- stub.yieldsTo(property, [arg1, arg2, ...])
- stub.yieldsToOn(property, context, [arg1, arg2, ...])
- stub.yield([arg1, arg2, ...])
- stub.yieldTo(callback, [arg1, arg2, ...])
- stub.callArg(argNum)
- stub.callArgWith(argNum, [arg1, arg2, ...])
- sinon.addBehavior(name, fn);
- stub.get(getterFn)
- stub.set(setterFn)
- stub.value(newVal)
- var clock = sinon.useFakeTimers();
- var clock = sinon.useFakeTimers(now);
- var clock = sinon.useFakeTimers(config);
- clock.tick(time); / await clock.tickAsync(time)
- clock.next(); / await clock.nextAsync()
- clock.runAll(); / await clock.runAllAsync()
- clock.restore();
- spy.withArgs(arg1[, arg2, ...]);
- spy.calledBefore(anotherSpy);
- spy.calledAfter(anotherSpy);
- spy.calledImmediatelyBefore(anotherSpy);
- spy.calledImmediatelyAfter(anotherSpy);
- spy.calledOn(obj);
- spy.alwaysCalledOn(obj);
- spy.calledWith(arg1, arg2, ...);
- spy.calledOnceWith(arg1, arg2, ...);
- spy.alwaysCalledWith(arg1, arg2, ...);
- spy.calledWithExactly(arg1, arg2, ...);
- spy.calledOnceWithExactly(arg1, arg2, ...);
- spy.alwaysCalledWithExactly(arg1, arg2, ...);
- spy.calledWithMatch(arg1, arg2, ...);
- spy.alwaysCalledWithMatch(arg1, arg2, ...);
- spy.calledWithNew();
- spy.neverCalledWith(arg1, arg2, ...);
- spy.neverCalledWithMatch(arg1, arg2, ...);
- spy.threw();
- "spy.threw(""TypeError"");"
- spy.threw(obj);
- spy.alwaysThrew();
- "spy.alwaysThrew(""TypeError"");"
- spy.alwaysThrew(obj);
- spy.returned(obj);
- spy.alwaysReturned(obj);
- var spyCall = spy.getCall(n);
- var spyCalls = spy.getCalls();
- spy.resetHistory();
- spy.restore();
- "spy.printf(""format string"", [arg1, arg2, ...]);"
- var xhr = sinon.useFakeXMLHttpRequest();
- xhr.onCreate = function (xhr) {};
- xhr.restore();
- FakeXMLHttpRequest.addFilter(fn)
- request.setStatus(status);
- request.setResponseHeaders(object);
- request.setResponseBody(body);
- request.respond(status, headers, body);
- request.error();
- var server = sinon.createFakeServer([config]);
- var server = sinon.createFakeServerWithClock();
- server.configure(config);
- server.respondWith(response);
- server.respondWith(url, response);
- server.respondWith(method, url, response);
- server.respondWith(urlRegExp, response);
- server.respondWith(method, urlRegExp, response);
- server.respond();
- server.getHTTPMethod(request)
- server.restore();
- sinon.restoreObject(object);
- sinon.createStubInstance(constructor);
- sinon.assert.fail(message)
- sinon.assert.pass(assertion);
- sinon.assert.notCalled(spy);
- sinon.assert.called(spy);
- sinon.assert.calledOnce(spy);
- sinon.assert.calledTwice(spy);
- sinon.assert.calledThrice(spy)
- sinon.assert.callCount(spy, num)
- sinon.assert.callOrder(spy1, spy2, ...)
- sinon.assert.calledOn(spyOrSpyCall, obj)
- sinon.assert.alwaysCalledOn(spy, obj)
- sinon.assert.calledWith(spyOrSpyCall, arg1, arg2, ...);
- sinon.assert.alwaysCalledWith(spy, arg1, arg2, ...);
- sinon.assert.neverCalledWith(spy, arg1, arg2, ...);
- sinon.assert.calledWithExactly(spyOrSpyCall, arg1, arg2, ...);
- sinon.assert.calledOnceWithExactly(spyOrSpyCall, arg1, arg2, ...);
- sinon.assert.alwaysCalledWithExactly(spy, arg1, arg2, ...);
- sinon.assert.calledWithMatch(spyOrSpyCall, arg1, arg2, ...)
- sinon.assert.alwaysCalledWithMatch(spy, arg1, arg2, ...)
- sinon.assert.calledWithNew(spyOrSpyCall)
- sinon.assert.neverCalledWithMatch(spy, arg1, arg2, ...)
- sinon.assert.threw(spyOrSpyCall, exception);
- sinon.assert.alwaysThrew(spy, exception);
- sinon.assert.match(actual, expectation);
- sinon.assert.expose(object, options);
- sinon.fake.returns(value);
- sinon.fake.throws(value);
- sinon.fake.resolves(value);
- sinon.fake.rejects(value);
- sinon.fake.yields([value1, ..., valueN]);
- sinon.fake.yieldsAsync([value1, ..., valueN]);
- sinon.fake(func);
- var sandbox = sinon.createSandbox();
- var sandbox = sinon.createSandbox(config);
- sandbox.assert();
- sandbox.replace(object, property, replacement);
- sandbox.replaceGetter();
- sandbox.replaceSetter();
- sandbox.spy();
- sandbox.createStubInstance();
- sandbox.stub();
- sandbox.mock();
- sandbox.useFakeTimers();
- sandbox.useFakeXMLHttpRequest();
- sandbox.useFakeServer();
- sandbox.usingPromise(promiseLibrary);
- sandbox.restore();
- sandbox.reset();
- sandbox.resetBehavior();
- sandbox.resetHistory();
- sandbox.verify();
- sandbox.verifyAndRestore();
- var spyCall = spy.getCall(n)
- spyCall.calledOn(obj);
- spyCall.calledWith(arg1, arg2, ...);
- spyCall.calledWithExactly(arg1, arg2, ...);
- spyCall.calledWithMatch(arg1, arg2, ...);
- spyCall.notCalledWith(arg1, arg2, ...);
- spyCall.notCalledWithMatch(arg1, arg2, ...);
- spyCall.returned(value);
- spyCall.threw();
- "spyCall.threw(""TypeError"");"
- spyCall.threw(obj);
- spyCall.calledBefore(otherCall)
- spyCall.calledAfter(otherCall)
- spyCall.calledImmediatelyBefore(otherCall)
- spyCall.calledImmediatelyAfter(otherCall)
- sinon.match(number);
- sinon.match(string);
- sinon.match(regexp);
- sinon.match(object);
- sinon.match(function)
- sinon.match.array.deepEquals(arr)
- sinon.match.array.startsWith(arr)
- sinon.match.array.endsWith(arr)
- sinon.match.array.contains(arr)
- sinon.match.map.deepEquals(map)
- sinon.match.map.contains(map)
- sinon.match.set.deepEquals(set)
- sinon.match.set.contains(set)
- sinon.match.in(array)
- sinon.match.same(ref)
- sinon.match.typeOf(type)
- sinon.match.instanceOf(type)
- sinon.match.has(property[, expectation])
- sinon.match.hasOwn(property[, expectation])
- sinon.match.hasNested(propertyPath[, expectation])
- sinon.match.every(matcher)
- sinon.match.some(matcher)
Property