1. chai-jest
Chai bindings for jest mocks.
chai-jest
Package: chai-jest
Created by: jwalton
Last modified: Wed, 27 Apr 2022 13:46:58 GMT
Version: 1.0.3
License: MIT
Downloads: 2,549
Repository: https://github.com/jwalton/chai-jest

Install

npm install chai-jest
yarn add chai-jest

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

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin