Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(console): export helper to manually suppress error output
Fixes #564
- Loading branch information
Showing
8 changed files
with
30 additions
and
24 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,32 @@ | ||
import filterConsole from 'filter-console' | ||
|
||
function suppressErrorOutput() { | ||
if (process.env.RHTL_DISABLE_ERROR_FILTERING) { | ||
return () => {} | ||
} | ||
|
||
return filterConsole( | ||
[ | ||
/^The above error occurred in the <TestComponent> component:/, // error boundary output | ||
/^Error: Uncaught .+/ // jsdom output | ||
], | ||
{ | ||
methods: ['error'] | ||
} | ||
) | ||
} | ||
|
||
function enableErrorOutputSuppression() { | ||
// Automatically registers console error suppression and restoration in supported testing frameworks | ||
if ( | ||
typeof beforeEach === 'function' && | ||
typeof afterEach === 'function' && | ||
!process.env.RHTL_DISABLE_ERROR_FILTERING | ||
) { | ||
let restoreConsole: () => void | ||
if (typeof beforeEach === 'function' && typeof afterEach === 'function') { | ||
let restoreConsole!: () => void | ||
|
||
beforeEach(() => { | ||
restoreConsole = filterConsole( | ||
[ | ||
/^The above error occurred in the <TestComponent> component:/, // error boundary output | ||
/^Error: Uncaught .+/ // jsdom output | ||
], | ||
{ | ||
methods: ['error'] | ||
} | ||
) | ||
restoreConsole = suppressErrorOutput() | ||
}) | ||
|
||
afterEach(() => restoreConsole?.()) | ||
afterEach(() => restoreConsole()) | ||
} | ||
} | ||
|
||
export { enableErrorOutputSuppression } | ||
export { enableErrorOutputSuppression, suppressErrorOutput } |
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
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
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
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
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
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
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