Skip to content

Commit 28cb379

Browse files
authored
Added a test for Profiler onRender that throws (facebook#13575)
1 parent 8963118 commit 28cb379

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

packages/react/src/__tests__/ReactProfiler-test.internal.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,40 @@ describe('Profiler', () => {
173173
loadModules({enableSchedulerTracking});
174174
});
175175

176+
it('should handle errors thrown', () => {
177+
const callback = jest.fn(id => {
178+
if (id === 'throw') {
179+
throw Error('expected');
180+
}
181+
});
182+
183+
let didMount = false;
184+
class ClassComponent extends React.Component {
185+
componentDidMount() {
186+
didMount = true;
187+
}
188+
render() {
189+
return this.props.children;
190+
}
191+
}
192+
193+
// Errors thrown from onRender should not break the commit phase,
194+
// Or prevent other lifecycles from being called.
195+
expect(() =>
196+
ReactTestRenderer.create(
197+
<ClassComponent>
198+
<React.unstable_Profiler id="do-not-throw" onRender={callback}>
199+
<React.unstable_Profiler id="throw" onRender={callback}>
200+
<div />
201+
</React.unstable_Profiler>
202+
</React.unstable_Profiler>
203+
</ClassComponent>,
204+
),
205+
).toThrow('expected');
206+
expect(didMount).toBe(true);
207+
expect(callback).toHaveBeenCalledTimes(2);
208+
});
209+
176210
it('is not invoked until the commit phase', () => {
177211
const callback = jest.fn();
178212

0 commit comments

Comments
 (0)