1.0.3 • Published 2 years ago

chai-jest v1.0.3

Weekly downloads
198
License
MIT
Repository
github
Last release
2 years ago

chai-jest

NPM version Build Status

Description

Adds functions for testing Jest mocks to chai.

If you're using chai with jest, but you still want access to the mock-related functions on jest's expect such as toHaveBeenCalled(), then this is for you.

Usage

import chai from 'chai';
import chaiJest from 'chai-jest';

chai.use(chaiJest);
const { expect } = chai;

describe('My test suite', () => {
    it('should test a jest mock', () => {
        const mock = jest.fn(() => true);

        mock();

        expect(mock).to.have.beenCalled;
        expect(mock).to.have.returnedWith(true);
    });
});

Assertions

  • beenCalled
  • beenCalledWith(...args: unknown[])
  • beenLastCalledWith(...args: unknown[])
  • beenNthCalledWith(nthCall: number, ...args: unknown[])
  • beenCalledTimes(times: number)
  • returned
  • returnedTimes(count: number)
  • returnedWith(expected: unknown)
  • lastReturnedWith(expected: unknown)
  • nthReturnedWith(nthCall: number, expected: unknown)

Copyright 2020 Jason Walton

1.0.3

2 years ago

1.0.2

3 years ago

1.0.1

4 years ago

1.0.0

4 years ago