Skip to content

Instantly share code, notes, and snippets.

@fabio-filho
Created February 25, 2021 13:59
Show Gist options
  • Save fabio-filho/1f2c6906469b0e35763dd1ea022b3b37 to your computer and use it in GitHub Desktop.
Save fabio-filho/1f2c6906469b0e35763dd1ea022b3b37 to your computer and use it in GitHub Desktop.
JavaScript - Overriding console functions to ignore propTypes errors and warnings
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