Adds jest
matchers for watching console
methods.
Install jest-plugin-console-matchers
using yarn
:
yarn add --dev jest-plugin-console-matchers
Adds the following matchers which check for console
methods to be called:
Matcher | Method |
---|---|
toConsoleError |
console.error |
toConsoleInfo |
console.info |
toConsoleLog |
console.log |
toConsoleWarn |
console.warn |
toThrowWarning |
warning |
If you want, you can import the matchers to install them in a set of tests.
import 'jest-plugin-console-matchers/setup';
If you want to install the matchers globally, you can modify the jest section of your package.json to include:
"jest": {
"setupFiles": [
"jest-plugin-console-matchers/setup"
]
}
Example spec that uses these matchers.
import 'jest-plugin-console-matchers/setup';
describe('User', () => {
set('user', () => new User());
describe('.sayHello', () => {
it('logs hello', () => {
expect(() => user.sayHello()).toConsoleLog();
});
});
describe('.delete', () => {
it('warns about deleting', () => {
expect(() => user.delete()).toConsoleWarn();
});
});
});
If you have any ideas on how this plugin could be better, create an Issue or submit a PR.