Need private packages and team management tools?Check out npm Teams »

hamjest-sinon

1.0.4 • Public • Published

Actions Status

Installation

npm install hamjest sinon hamjest-sinon --save-dev

Usage

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());

Sinon matchers

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.

wasCalled(valueOrMatcher)

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()));

wasCalledWith(valueOrMatcher)

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())));

wasCalledInOrder(valueOrMatcher)

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));

Install

npm i hamjest-sinon

DownloadsWeekly Downloads

0

Version

1.0.4

License

MIT

Unpacked Size

26.6 kB

Total Files

15

Last publish

Collaborators

  • avatar