Skip to content

Instantly share code, notes, and snippets.

@psenger
Last active January 19, 2021 00:11
Show Gist options
  • Select an option

  • Save psenger/f4b423a9699f339c8d8d2c32e1ad0113 to your computer and use it in GitHub Desktop.

Select an option

Save psenger/f4b423a9699f339c8d8d2c32e1ad0113 to your computer and use it in GitHub Desktop.
[Jest - How to Monitor Console] #Jest
const warnConsole = jest.spyOn(console, "warn").mockImplementation(() => {});
const errorConsole = jest.spyOn(console, "error").mockImplementation(() => {});
const infoConsole = jest.spyOn(console, "info").mockImplementation(() => {});
expect(warnConsole).toBeCalledWith('...');
expect(errorConsole).toBeCalledWith('...');
expect(infoConsole).toBeCalledWith('...');
expect(warnConsole).not.toHaveBeenCalled();
expect(errorConsole).not.toHaveBeenCalled();
expect(infoConsole).not.toHaveBeenCalled();
warnConsole.mockReset();
errorConsole.mockReset();
infoConsole.mockReset();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment