mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Basic SSR support for error boundaries (#6694)
This commit is contained in:
@@ -13,11 +13,13 @@
|
||||
|
||||
var React;
|
||||
var ReactDOM;
|
||||
var ReactDOMServer;
|
||||
|
||||
describe('ReactErrorBoundaries', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
ReactDOM = require('ReactDOM');
|
||||
ReactDOMServer = require('ReactDOMServer');
|
||||
React = require('React');
|
||||
});
|
||||
|
||||
@@ -55,6 +57,41 @@ describe('ReactErrorBoundaries', function() {
|
||||
expect(EventPluginHub.putListener).not.toBeCalled();
|
||||
});
|
||||
|
||||
it('renders an error state (ssr)', function() {
|
||||
class Angry extends React.Component {
|
||||
render() {
|
||||
throw new Error('Please, do not render me.');
|
||||
}
|
||||
}
|
||||
|
||||
class Boundary extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {error: false};
|
||||
}
|
||||
render() {
|
||||
if (!this.state.error) {
|
||||
return (<div><button onClick={this.onClick}>ClickMe</button><Angry /></div>);
|
||||
} else {
|
||||
return (<div>Happy Birthday!</div>);
|
||||
}
|
||||
}
|
||||
onClick() {
|
||||
/* do nothing */
|
||||
}
|
||||
unstable_handleError() {
|
||||
this.setState({error: true});
|
||||
}
|
||||
}
|
||||
|
||||
var EventPluginHub = require('EventPluginHub');
|
||||
var container = document.createElement('div');
|
||||
EventPluginHub.putListener = jest.fn();
|
||||
container.innerHTML = ReactDOMServer.renderToString(<Boundary />);
|
||||
expect(container.firstChild.innerHTML).toBe('Happy Birthday!');
|
||||
expect(EventPluginHub.putListener).not.toBeCalled();
|
||||
});
|
||||
|
||||
it('will catch exceptions in componentWillUnmount', function() {
|
||||
class ErrorBoundary extends React.Component {
|
||||
constructor() {
|
||||
|
||||
@@ -60,6 +60,12 @@ var Mixin = {
|
||||
*/
|
||||
destructor: function() {
|
||||
},
|
||||
|
||||
checkpoint: function() {
|
||||
},
|
||||
|
||||
rollback: function() {
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user