Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/posva/jest-mock-warn

Mock console.log warn calls and assert their calls
https://github.com/posva/jest-mock-warn

console jest mock test vue

Last synced: about 1 month ago
JSON representation

Mock console.log warn calls and assert their calls

Awesome Lists containing this project

README

        

# jest-mock-warn [![npm package](https://badgen.net/npm/v/jest-mock-warn)](https://www.npmjs.com/package/jest-mock-warn)

> mock `console.warn`

## Installation

```sh
yarn add -D jest-mock-warn
```

## Usage

```js
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](http://opensource.org/licenses/MIT)