1. jest-mock-warn
Assert console.warn calls
jest-mock-warn
Package: jest-mock-warn
Created by: posva
Last modified: Fri, 06 May 2022 12:35:25 GMT
Version: 1.1.0
License: MIT
Downloads: 154
Repository: https://github.com/posva/jest-mock-warn

Install

npm install jest-mock-warn
yarn add jest-mock-warn

jest-mock-warn npm package

mock console.warn

Installation

 yarn add -D jest-mock-warn

Usage

 import { mockWarn } from 'jest-mock-warn'

function myFunction() {
  if (!arguments.length) console.warn('provide an argument')
}

describe('my tests', () => {
  mockWarn()
  it('warns when called without arguments', () => {
    myFunction()
    expect('provide an argument').toHaveBeenWarned()
    expect('provide an argument').toHaveBeenWarnedTimes(1)
    expect('provide an argument').toHaveBeenLastWarned()
  })
})

API

  • toHaveBeenWarned()
  • toHaveBeenWarnedLast()
  • toHaveBeenWarnedTimes(n: number)

License

MIT

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