-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Suppressing error boundary logs doesn't work with enzyme-adapter-react-16 #1826
Comments
I'm confused why you'd need to suppress them - if you're wrapping an error boundary, then your error boundary gets the error information in its I don't think that workaround is particularly useful; your tests should be exercising your error boundaries the same way they'd be used in production. In other words, i'd expect you to mount or shallow around an ErrorBoundary that wrapped your component-under-test, and use your tests to assert on what arguments componentDidCatch received. See enzyme's own tests for an example: https://github.com/airbnb/enzyme/blob/master/packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx#L5112-L5146 |
The problem is the logging of the error boundary output, e.g.
Even though it looks ugly, mocha is fine with it and the tests succeed. However, when running the test in Karma it fails. Thanks for that code pointer, @ljharb! I didn't know about enzymes I'm now wondering why I can't find the specific ErrorBoundary: class ErrorBoundary extends React.Component {
constructor(props) {
super(props)
this.state = { hasError: false }
}
componentDidCatch() {
this.setState({ hasError: true })
}
render() {
if (this.state.hasError) {
return <ErrorInfo />
}
return this.props.children
}
} Test it('should render the ErrorInfo component on error', () => {
const wrapper = mount(
<PageErrorBoundary>
<Child />
</PageErrorBoundary>)
expect(() => wrapper.find(Child).simulateError(DummyError)).not.to.throw()
console.log(wrapper.html()) // output looks perfectly fine
expect(wrapper.find(ErrorInfo)).to.have.lengthOf(1) // fails
}) |
Apparently, I need to call |
This is a cross-post from the React issue tracker
Describe the bug
In React 16.5, @gaearon added a way to suppress error bounday logs in tests (described in this issue].
Unfortunately, this doesn't work when importing
enzyme-adapter-react-16
. The import is enough for it to fail.To Reproduce
Steps to reproduce the behavior:
yarn install
yarn test
Expected behavior
I expect the error to be swallowed and counted by the global error handler in
expectRenderError
.Instead, the error is shown as before. When not importing the adapter, everything is working fine.
The text was updated successfully, but these errors were encountered: