hamjest-sinon
    TypeScript icon, indicating that this package has built-in type declarations

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

    License

    Licensed under the MIT License (enclosed).

    This library is inspired by and based on the work of Hamjest.

    Install

    npm i hamjest-sinon

    DownloadsWeekly Downloads

    535

    Version

    1.0.6

    License

    MIT

    Unpacked Size

    27.8 kB

    Total Files

    18

    Last publish

    Collaborators

    • mafo5