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: 186
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

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code