Skip to content

Commit 4d351a7

Browse files
committed
[noop] Fail tests on unasserted recoverable errors
1 parent fe1ec4f commit 4d351a7

4 files changed

Lines changed: 30 additions & 4 deletions

File tree

packages/react-noop-renderer/src/createReactNoop.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,8 +1173,8 @@ function createReactNoop(
11731173
}
11741174

11751175
function onRecoverableError(error: mixed): void {
1176-
// TODO: Turn this on once tests are fixed
1177-
// console.error(error);
1176+
// eslint-disable-next-line react-internal/warning-args, react-internal/no-production-logging -- renderer is only used for testing.
1177+
console.error(error);
11781178
}
11791179
function onDefaultTransitionIndicator(): void | (() => void) {}
11801180

packages/react-reconciler/src/__tests__/ReactIncrementalErrorHandling-test.internal.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,10 @@ describe('ReactIncrementalErrorHandling', () => {
287287
'commit',
288288
'commit',
289289
]);
290+
assertConsoleErrorDev([
291+
'Error: There was an error during concurrent rendering but React was able to recover by instead synchronously rendering the entire root.' +
292+
'\n in <stack>',
293+
]);
290294
expect(ReactNoop).toMatchRenderedOutput(
291295
<span prop="Everything is fine." />,
292296
);
@@ -339,6 +343,10 @@ describe('ReactIncrementalErrorHandling', () => {
339343
'commit',
340344
'commit',
341345
]);
346+
assertConsoleErrorDev([
347+
'Error: There was an error during concurrent rendering but React was able to recover by instead synchronously rendering the entire root.' +
348+
'\n in <stack>',
349+
]);
342350
// This should not include the offscreen content
343351
expect(ReactNoop).toMatchRenderedOutput(
344352
<>
@@ -1786,6 +1794,10 @@ describe('ReactIncrementalErrorHandling', () => {
17861794
});
17871795

17881796
// Should finish without throwing.
1797+
assertConsoleErrorDev([
1798+
'Error: There was an error during concurrent rendering but React was able to recover by instead synchronously rendering the entire root.' +
1799+
'\n in <stack>',
1800+
]);
17891801
expect(root).toMatchRenderedOutput('Everything is fine.');
17901802
});
17911803

@@ -1832,6 +1844,10 @@ describe('ReactIncrementalErrorHandling', () => {
18321844
});
18331845
// Should render the final state without throwing the error.
18341846
assertLog(['Everything is fine.']);
1847+
assertConsoleErrorDev([
1848+
'Error: There was an error during concurrent rendering but React was able to recover by instead synchronously rendering the entire root.' +
1849+
'\n in <stack>',
1850+
]);
18351851
expect(root).toMatchRenderedOutput('Everything is fine.');
18361852
});
18371853

packages/react-reconciler/src/__tests__/ReactIncrementalErrorReplay-test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
let React;
1414
let ReactNoop;
15+
let assertConsoleErrorDev;
1516
let waitForAll;
1617
let waitForThrow;
1718

@@ -22,6 +23,7 @@ describe('ReactIncrementalErrorReplay', () => {
2223
ReactNoop = require('react-noop-renderer');
2324

2425
const InternalTestUtils = require('internal-test-utils');
26+
assertConsoleErrorDev = InternalTestUtils.assertConsoleErrorDev;
2527
waitForAll = InternalTestUtils.waitForAll;
2628
waitForThrow = InternalTestUtils.waitForThrow;
2729
});
@@ -50,5 +52,9 @@ describe('ReactIncrementalErrorReplay', () => {
5052
}
5153
ReactNoop.render(<App />);
5254
await waitForAll([]);
55+
assertConsoleErrorDev([
56+
'Error: There was an error during concurrent rendering but React was able to recover by instead synchronously rendering the entire root.' +
57+
'\n in <stack>',
58+
]);
5359
});
5460
});

packages/react-reconciler/src/__tests__/useMemoCache-test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
* @jest-environment node
99
*/
1010

11+
import {assertConsoleErrorDev} from 'internal-test-utils';
12+
1113
let React;
1214
let ReactNoop;
1315
let Scheduler;
@@ -256,8 +258,6 @@ describe('useMemoCache()', () => {
256258
return `${data.text} (n=${props.n})`;
257259
});
258260

259-
spyOnDev(console, 'error');
260-
261261
const root = ReactNoop.createRoot();
262262
await act(() => {
263263
root.render(
@@ -274,6 +274,10 @@ describe('useMemoCache()', () => {
274274
// this triggers a throw.
275275
setN(1);
276276
});
277+
assertConsoleErrorDev([
278+
'Error: There was an error during concurrent rendering but React was able to recover by instead synchronously rendering the entire root.' +
279+
'\n in <stack>',
280+
]);
277281
expect(root).toMatchRenderedOutput('Count 0 (n=1)');
278282
expect(Text).toBeCalledTimes(2);
279283
expect(data).toBe(data0);

0 commit comments

Comments
 (0)