Skip to content

Commit

Permalink
Added a test for Profiler onRender that throws (facebook#13575)
Browse files Browse the repository at this point in the history
  • Loading branch information
bvaughn authored and jetoneza committed Jan 23, 2019
1 parent 33b3869 commit 8435968
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions packages/react/src/__tests__/ReactProfiler-test.internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,40 @@ describe('Profiler', () => {
loadModules({enableSchedulerTracking});
});

it('should handle errors thrown', () => {
const callback = jest.fn(id => {
if (id === 'throw') {
throw Error('expected');
}
});

let didMount = false;
class ClassComponent extends React.Component {
componentDidMount() {
didMount = true;
}
render() {
return this.props.children;
}
}

// Errors thrown from onRender should not break the commit phase,
// Or prevent other lifecycles from being called.
expect(() =>
ReactTestRenderer.create(
<ClassComponent>
<React.unstable_Profiler id="do-not-throw" onRender={callback}>
<React.unstable_Profiler id="throw" onRender={callback}>
<div />
</React.unstable_Profiler>
</React.unstable_Profiler>
</ClassComponent>,
),
).toThrow('expected');
expect(didMount).toBe(true);
expect(callback).toHaveBeenCalledTimes(2);
});

it('is not invoked until the commit phase', () => {
const callback = jest.fn();

Expand Down

0 comments on commit 8435968

Please sign in to comment.