Created
February 25, 2020 20:49
-
-
Save mahowa/d6548313768f33f6b8f1fad1c51f705a to your computer and use it in GitHub Desktop.
Jest test for console.warn & console.error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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