npm install hamjest sinon hamjest-sinon --save-dev
Add the sinon matcher to hamjest by require the module
const __ = require('hamjest');
// auto extend hamjest
require('hamjest-sinon');
// or
require('hamjest-sinon').extendHamjest(__);
// use matcher from hamjest
__.assertThat(stub, __.wasCalled());
Mock matchers is an extension to Sinon matchers which supports the Jest Mock as well.
Sinon matchers are used for testing function calls. Replace the function with a sinon stub or spy and assert the call of the function by your code with these matchers.
Assert that a sinon stub was called:
__.assertThat(stub, __.wasCalled());
Assert that a sinon stub was called a specific amount of times:
__.assertThat(stub, __.wasCalled(2));
Assert that a sinon stub was called a variable amount of times:
__.assertThat(stub, __.wasCalled(__.greaterThan(1)));
Assert that a sinon stub was not called:
__.assertThat(stub, __.wasCalled(0));
// or
__.assertThat(stub, __.not(__.wasCalled()));
Assert that a sinon stub was called with empty args:
__.assertThat(stub, __.wasCalledWith());
// or
__.assertThat(stub, __.wasCalledWith(__.undefined()));
Assert that a sinon stub was called with a specific arg:
__.assertThat(stub, __.wasCalledWith('something'));
Assert that a sinon stub was called a variable arg:
__.assertThat(stub, __.wasCalledWith(__.containsString('something')));
Assert that a sinon stub was not called with empty arg:
__.assertThat(stub, __.not(__.wasCalledWith()));
// or
__.assertThat(stub, __.not(__.wasCalledWith(__.undefined())));
Assert that a sinon stub was called in order with specific args:
__.assertThat(stub, __.wasCalledInOrder('first call with args', 'second call with args'));
Assert that a sinon stub was called in order with variable args:
__.assertThat(stub, __.wasCalledInOrder(__.containsString('first'), __.containsString('second')));
Assert that a sinon stub was not called:
__.assertThat(stub, __.wasCalledInOrder());
// or
__.assertThat(stub, __.wasCalled(0));
Licensed under the MIT License (enclosed).
This library is inspired by and based on the work of Hamjest.