Miss any of our Open RFC calls?Watch the recordings here! »

jest-plugin-console-matchers

2.9.0 • Public • Published

jest-plugin-console-matchers

npm npm npm

Adds jest matchers for watching console methods.

Getting Started

Install jest-plugin-console-matchers using yarn:

yarn add --dev jest-plugin-console-matchers

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

Usage

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

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();
    });
  });
});

Contributing

If you have any ideas on how this plugin could be better, create an Issue or submit a PR.

Install

npm i jest-plugin-console-matchers

DownloadsWeekly Downloads

742

Version

2.9.0

License

MIT

Unpacked Size

4.05 kB

Total Files

6

Last publish

Collaborators

  • avatar