npm.io
1.1.0 • Published 6 years ago

jest-mock-warn

Licence
MIT
Version
1.1.0
Deps
0
Size
6 kB
Vulns
0
Weekly
0

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

Keywords