Created
February 25, 2021 13:59
-
-
Save fabio-filho/1f2c6906469b0e35763dd1ea022b3b37 to your computer and use it in GitHub Desktop.
JavaScript - Overriding console functions to ignore propTypes errors and warnings
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
const originalConsoleWarn = console.warn; | |
global.console.warn = (...args) => { | |
const propTypeFailures = [/Warning: componentWillMount/]; | |
if (propTypeFailures.some(p => p.test(args[0]))) { | |
return; | |
} | |
originalConsoleWarn.call(console, ...args); | |
}; | |
// eslint-disable-next-line no-console | |
const originalConsoleError = console.error; | |
global.console.error = (...args) => { | |
const propTypeFailures = [/Failed prop type/, /Warning: Received/]; | |
if (propTypeFailures.some(p => p.test(args[0]))) { | |
return; | |
} | |
originalConsoleError.call(console, ...args); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment