-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Enzyme 3 couldn't test component when ComponentDidCatch happend #1255
Copy link
Copy link
Closed
Description
My Component:
class Error extends React.Component {
render() {
throw new Error('ErrorMessage');
return <div />;
}
}
class App extends React.Component {
constructor() {
super();
this.state = {
hasError: false,
error: null,
errorInfo: null
}
}
componentDidCatch(error, info) {
this.setState({
hasError: true,
error,
errorInfo: info
});
}
render() {
const { hasError } = this.state;
if (this.state.hasError) {
return <div className="error-view">error view</div>
}
return <Error />
}
}My test:
const app = mount(<App />);
const errorTip = app.setState({
hasError: true,
});
expect(app.find('.error-view').length).to.equal(1);When app is mount,app throws the error and I couldn't get the app to test the error view. How do I solve it?
Reactions are currently unavailable