/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @emails react-core * @jest-environment node */ 'use strict'; let React; let ReactNoop; let assertConsoleErrorDev; let waitForAll; let waitForThrow; describe('ReactIncrementalErrorReplay', () => { beforeEach(() => { jest.resetModules(); React = require('react'); ReactNoop = require('react-noop-renderer'); const InternalTestUtils = require('internal-test-utils'); assertConsoleErrorDev = InternalTestUtils.assertConsoleErrorDev; waitForAll = InternalTestUtils.waitForAll; waitForThrow = InternalTestUtils.waitForThrow; }); it('should fail gracefully on error in the host environment', async () => { ReactNoop.render(); await waitForThrow('Error in host config.'); }); it("should ignore error if it doesn't throw on retry", async () => { let didInit = false; function badLazyInit() { const needsInit = !didInit; didInit = true; if (needsInit) { throw new Error('Hi'); } } class App extends React.Component { render() { badLazyInit(); return
; } } ReactNoop.render(); await waitForAll([]); assertConsoleErrorDev([ 'Error: There was an error during concurrent rendering but React was able to recover by instead synchronously rendering the entire root.' + '\n in ', ]); }); });