Created
December 7, 2023 19:25
-
-
Save smarquez1/f75006f96a3f1663d765fcede8602d8e to your computer and use it in GitHub Desktop.
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
// 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