Skip to content

Commit

Permalink
Added a test for Profiler onRender that throws (#13575)
Browse files Browse the repository at this point in the history
  • Loading branch information
bvaughn authored Sep 6, 2018
1 parent 8963118 commit 28cb379
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 28cb379

Please sign in to comment.