Skip to content

Commit

Permalink
Add regression tests for error boundary replay bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Apr 1, 2018
1 parent 7d31311 commit 3693ab9
Showing 1 changed file with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @emails react-core
* @jest-environment node
*/

'use strict';

let ReactFeatureFlags;
let React;
let ReactNoop;

describe('ReactIncrementalErrorReplay', () => {
beforeEach(() => {
jest.resetModules();
React = require('react');
ReactNoop = require('react-noop-renderer');
});

function div(...children) {
children = children.map(c => (typeof c === 'string' ? {text: c} : c));
return {type: 'div', children, prop: undefined};
}

function span(prop) {
return {type: 'span', children: [], prop};
}

it('should fail gracefully on error in the host environment', () => {
ReactNoop.simulateErrorInHostConfig(() => {
ReactNoop.render(<span />);
expect(() => ReactNoop.flush()).toThrow('Error in host config.');
});
});

it('should fail gracefully on error that does not reproduce on replay', () => {
let index = 0;

class App extends React.Component {
render() {
if (index === 0) {
index++;
throw new Error('Hi');
}

return (
<div>
<h1>Hello, {this.props.name}</h1>
</div>
);
}
}
ReactNoop.render(<App />);
expect(() => ReactNoop.flush()).toThrow('Hi');
});
});

0 comments on commit 3693ab9

Please sign in to comment.