Added a test for Profiler onRender that throws (#13575)
Brian Vaughn committed
Sep 6, 2018 at 08:03 UTC
28cb37978219584fc5b3e296aa87810d567fd3ec
1 file changed
+34
packages/react/src/__tests__/ReactProfiler-test.internal.js
+34
@@ -173,6 +173,40 @@ describe('Profiler', () => {
173
loadModules({enableSchedulerTracking});
174
});
175
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
+
210
it('is not invoked until the commit phase', () => {
211
const callback = jest.fn();
212