Skip to content

Instantly share code, notes, and snippets.

@smarquez1
Created December 7, 2023 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smarquez1/f75006f96a3f1663d765fcede8602d8e to your computer and use it in GitHub Desktop.
Save smarquez1/f75006f96a3f1663d765fcede8602d8e to your computer and use it in GitHub Desktop.
// eslint-disable no-console
// https://github.com/facebook/react/pull/22114#issuecomment-900721521
// This error is a bug fixed in React 18: https://github.com/facebook/react/pull/22114.
// Suppress it for all tests.
const KNOWN_VIOLATIONS = [
"Warning: Can't perform a React state update on an unmounted",
];
const configureConsoleError = (silenceKnownErrors = true) => {
if (silenceKnownErrors) {
const oldError = console.error;
console.error = (...args) => {
const firstArg = args[0];
if (
typeof firstArg === 'string' &&
KNOWN_VIOLATIONS.some((v) => firstArg.includes(v))
) {
return;
}
oldError(...args);
};
}
};
export default configureConsoleError;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment