Back to Sinon

assert.callOrder

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

22.1.0747 B
Original Source

assert.callOrder(spy1, spy2, ...);

Passes, when provided fakes, spies or stubs are called in the specified order.

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

fake();
spy();
stub();

// not the called order
sinon.assert.callOrder(spy, stub, fake);
// => Uncaught: Error [AssertError]: expected spy, stub, fake to be called in order but were called as fake, spy, stub

// the called order - generates no error
sinon.assert.callOrder(fake, spy, stub);

Example using test framework

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