Skip to content

Latest commit

 

History

History

jest-plugin-console-matchers

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

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.