Back to Sinon

assert.calledWithExactly

docs/concepts/assertions/api/called-with-exactly.md

22.1.01.4 KB
Original Source

assert.calledWithExactly(spyOrSpyCall, arg1, arg2, ...);

Passes, when the fake, spy or stub was called with exactly the provided arguments.

It's possible to assert on a dedicated spyCall: sinon.assert.calledWithExactly(call, arg1, arg2, ...);.

js
import * as sinon from "sinon";
const fake = sinon.fake();

sinon.assert.calledWithExactly(fake, "apple pie");
// => Uncaught Error [AssertError]: expected fake to be called with exact arguments

fake("apple pie");

// Generates no error
sinon.assert.calledWithExactly(fake, "apple pie");

sinon.assert.calledWithExactly(fake, "lemon meringue pie");
// => Uncaught Error [AssertError]: expected fake to be called with exact arguments
// => '"apple pie"' '"lemon meringue pie"'

// reset the history of everything
sinon.resetHistory();

sinon.assert.calledWithExactly(fake, "apple pie");
// => Uncaught Error [AssertError]: expected fake to be called with exact arguments

Asserting on a spyCall

js
import * as sinon from "sinon";
const fake = sinon.fake();

fake("apple pie");

// get a spyCall instance
const call = fake.firstCall;

// Generates no error
sinon.assert.calledWithExactly(call, "apple pie");

Example using test framework

<<< ../../../.vitepress/tests/docs/assertions/api/called-with-exactly.test.js