Back to Sinon

assert.callCount

docs/concepts/assertions/api/call-count.md

22.1.0560 B
Original Source

assert.callCount(spy, num);

Passes if the fake, spy or stub was called exactly num times.

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

sinon.assert.callCount(spy, 1);
// => Uncaught Error [AssertError]: expected spy to be called once but was called 0 times

spy();
// Generates no exception
sinon.assert.callCount(spy, 1);

Example using test framework

<<< ../../../.vitepress/tests/docs/assertions/api/call-count.test.js