Back to Sinon

assert.alwaysCalledWithMatch

docs/concepts/assertions/api/always-called-with-match.md

22.1.01.1 KB
Original Source

assert.alwaysCalledWithMatch(spy, arg1, arg2, ...)

Passes, when the fake, spy or stub was always called with matching arguments.

This behaves the same way as sinon.assert.alwaysCalledWith(spy, sinon.match(arg1), sinon.match(arg2), ...).

js
import * as sinon from "sinon";
const fake = sinon.fake();
const applePieExpectation = {
  name: "apple pie"
};

fake({
  name: "apple pie",
  price: 123
});

// Matches, generates no error
sinon.assert.alwaysCalledWithMatch(fake, applePieExpectation);

fake({
  name: "cherry pie",
  price: 123
});

sinon.assert.alwaysCalledWithMatch(fake, applePieExpectation);
//=> Uncaught Error [AssertError]: expected fake to always be called with match
//=> Call 1:
//=> { name: 'apple pie', price: 123 } { name: 'apple pie' }
//=> Call 2:
//=> { name: 'cherry pie', price: 123 } { name: 'apple pie' }

Example using test framework

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