-
Notifications
You must be signed in to change notification settings - Fork 47.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add regression tests for error boundary replay bugs
- Loading branch information
Showing
1 changed file
with
60 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
packages/react-reconciler/src/__tests__/ReactIncrementalErrorReplay-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); |