-
Notifications
You must be signed in to change notification settings - Fork 47.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot suppress error boundary output using react-test-renderer #15520
Comments
Bumping this. I'm trying to solve this in Rut, but it's turning out to be quite difficult (I'm not using JSDOM). https://github.com/milesj/rut |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution. |
😭 |
An ugly workaround while waiting for a proper fix here is to temporarily replace A util function like this works for both this issue and another issue of coverage not being counted in // In test utils
const consoleError = console.error
function catchErrorSilently(fn) {
try {
console.error = () => {}
fn()
} catch (error) {
return error
} finally {
console.error = consoleError
}
}
// In tests:
expect(catchErrorSilently(() =>
render(<SomeComponent someProp="invalid prop value" />)
)).toBeInstanceOf(Error) Or for a broader scope: const consoleError = console.error
beforeEach(() => {
console.error = () => {}
})
afterEach(() => {
console.error = consoleError
}) |
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment! |
No stalebot, not stake... Ignored... Ignored is the word you're looking for. Almost a year now and nothing. Is the test renderer even supported any more? |
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment! |
Bump. |
This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment! |
Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you! |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
When following @gaearon's example on how to suppress the error boundary logging in tests expecting errors, it appears to not be working in 16.8.6 (I'm not sure which versions after 16.4.3 is has worked for).
Here is a sandbox.
I had to make a change to the
renderError
as it looks like the way codesandbox executes the script cause theevent.error
to be hidden from the code (it just had an object withisTrusted: true
on it - google led me here so I changed it to just count the number of errors).I also made a change to be able to use
react-test-renderer
as well asreact-dom
as I'm actually after a way to suppress the error using the test renderer for an issue raised inreact-hooks-testing-library
.In my sandbox, you will see the errors
and
get printed to the console, despite the
event.preventDefault()
call.The other main thing to note is that the
react-test-renderer
test does not pass, which implies the error listener is not firing for it, which sort of makes sense to me as it's not using the DOM, so it's not erroring on the window, but my understanding of these things is somewhat limited.What is the expected behavior?
Assuming the
expectRenderError
,TestBoundary
andhandleTopLevelError
code is sufficient to suppress the output as indicated in #11098, I would expect thereact-dom
test to produce no output.Assuming the same setup should also work for
react-test-renderer
, I would also expect that test to have no output.If either of these assumptions are wrong, how should one go about suppressing the output in these tests?
Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
react
:16.8.6
react-dom
:16.8.6
react-test-renderer
:16.8.6
The text was updated successfully, but these errors were encountered: