chai-callslike
    TypeScript icon, indicating that this package has built-in type declarations

    1.2.7 • Public • Published

    chai-callslike

    build test lint Test Coverage Maintainability Packages npm version

    A simple assertion to validate many aspects of stub calls. It is supposed to use with sinon + chai.

    How it works

    expect(stub).callsLike

    Will validate the exactly interaction with the mocked method, which is:

    • How many times has been called;
    • Which parameters have been passed to it;
    • In what order the calls happened.

    How to use?

    Just pass the stub in the first parameter and, in the others, arrays with the set of parameters each calls had received.

    expect(myStub).callsLike(
      ['param1call1', 'param2call1', 'param3call1'],
      ['param1call2', 'param2call2', 'param3call2'],
     );
    

    If you want to check if the stub had never been called, pass just the stub:

    expect(myStub).callsLike();
    

    If you expect the stub to have been called with no parameters, pass empty arrays:

    expect(myStub).callsLike([], [], [])
    

    (in this example, myStub have been called three times with no parameters)

    You can also use sinon matchers to validate the parameters instead of exact values:

    expect(myStub).callsLike(
      [sinon.match.object, sinon.match.string, sinon.match(/.+foo.+goo/)]
     );
    

    The generated log will look pretty as this:

    If if didn't show up, take a look in the resources folder!

    For more info look into the Full API Reference.

    Install

    npm i chai-callslike

    DownloadsWeekly Downloads

    165

    Version

    1.2.7

    License

    MIT

    Unpacked Size

    36 kB

    Total Files

    61

    Last publish

    Collaborators

    • pedrosodre
    • danielcarvalho
    • gustavobeavis
    • paulododt
    • fgabrielsilva
    • danielgaleni
    • farenheith
    • jeocoutinho