Nomenclature Processing Machine

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

    1.2.4 • Public • Published

    chai-jest-mocks

    npm version CircleCI Coverage Status

    Chai plugin that adds assertions for jest mock functions

    NOTE this is still very much a work in progress, more matchers and better documentation (and tests) are coming!

    Installation

    On the command line:

    $ npm install --save-dev chai-jest-mocks
    

    Usage

    First, tell chai that you want to use chai-jest-mocks

    const chai = require('chai');
    const chaiJestMock = require('chai-jest-mocks');
     
    chai.use(chaiJestMock);

    Then you will have access to the new assertions:

    // Expect a mock to be called
    expect(mockFn).to.have.beenCalled();
     
    // Expect a mock to have been called a certain number of times
    expect(mockFn).to.have.beenCalledTimes(4);
     
    // Expect a mock to have been called with specific arguments
    expect(mockFn).to.have.beenCalledWith('hello', 'world');
     
    // Expect a mock to have been last called with specific arguments
    expect(mockFn).to.have.beenLastCalledWith('hello', 'world');
     
    // Expect a mock to have been nth (in this case, second) called with specific arguments
    expect(mockFn).to.have.beenNthCalledWith(2, 'hello', 'world');
     
    // Expect a mock to have returned succesfully (i.e, not throw)
    expect(mockFn).to.have.returned();
     
    // Expect a mock to have returned succesfully a certain number of times
    expect(mockFn).to.have.returnedTimes(3);

    Install

    npm i chai-jest-mocks

    DownloadsWeekly Downloads

    253

    Version

    1.2.4

    License

    MIT

    Unpacked Size

    15.1 kB

    Total Files

    22

    Last publish

    Collaborators

    • caffeinatedcm