Skip to content

Instantly share code, notes, and snippets.

@mahowa
Created February 25, 2020 20:49
Show Gist options
  • Save mahowa/d6548313768f33f6b8f1fad1c51f705a to your computer and use it in GitHub Desktop.
Save mahowa/d6548313768f33f6b8f1fad1c51f705a to your computer and use it in GitHub Desktop.
Jest test for console.warn & console.error
// In case you are tired of seeing warning and error messages in your tests add these
// few lines of code to your setupTests.js file.
//
// Any test that outputs console.error or console.warn will fail allowing you to easily
// identify where the log came from so you can address it accordingly
const spyError = jest.spyOn(global.console, 'error');
const spyWarn = jest.spyOn(global.console, 'warn');
afterEach(() => {
resetAxiosResponse();
expect(spyError).not.toHaveBeenCalled();
expect(spyWarn).not.toHaveBeenCalled();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment