1.1.0 • Published 7 years ago

jest-console-matchers v1.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

jest-console-matchers

npm npm npm CircleCI branch

Adds jest matchers for watching console methods.

Getting Started

Install jest-console-matchers using yarn:

yarn add --dev jest-console-matchers

Matchers

Adds the following matchers which check for console methods to be called:

MatcherMethod
toConsoleDebugconsole.debug
toConsoleErrorconsole.error
toConsoleLogconsole.log
toConsoleWarnconsole.warn
toThrowWarningwarning

Usage

Example spec that uses these matchers.

import 'jest-console-matchers';

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 package could be better, create an Issue or submit a PR.