main
js 60 lines 1.54 KB
Raw
1 /**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @emails react-core
8 * @jest-environment node
9 */
10
11 'use strict';
12
13 let React;
14 let ReactNoop;
15 let assertConsoleErrorDev;
16 let waitForAll;
17 let waitForThrow;
18
19 describe('ReactIncrementalErrorReplay', () => {
20 beforeEach(() => {
21 jest.resetModules();
22 React = require('react');
23 ReactNoop = require('react-noop-renderer');
24
25 const InternalTestUtils = require('internal-test-utils');
26 assertConsoleErrorDev = InternalTestUtils.assertConsoleErrorDev;
27 waitForAll = InternalTestUtils.waitForAll;
28 waitForThrow = InternalTestUtils.waitForThrow;
29 });
30
31 it('should fail gracefully on error in the host environment', async () => {
32 ReactNoop.render(<errorInBeginPhase />);
33 await waitForThrow('Error in host config.');
34 });
35
36 it("should ignore error if it doesn't throw on retry", async () => {
37 let didInit = false;
38
39 function badLazyInit() {
40 const needsInit = !didInit;
41 didInit = true;
42 if (needsInit) {
43 throw new Error('Hi');
44 }
45 }
46
47 class App extends React.Component {
48 render() {
49 badLazyInit();
50 return <div />;
51 }
52 }
53 ReactNoop.render(<App />);
54 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 ]);
59 });
60 });