Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/posva/jest-mock-warn
- Owner: posva
- License: mit
- Created: 2020-02-05T16:33:47.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-06-23T08:02:19.000Z (over 4 years ago)
- Last Synced: 2024-12-30T15:44:26.472Z (about 1 month ago)
- Topics: console, jest, mock, test, vue
- Language: JavaScript
- Size: 9.77 KB
- Stars: 10
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
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)