Skip to content

Commit

Permalink
Convert ReactErrorBoundariesHooks to createRoot (#28175)
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon authored and gaearon committed Feb 3, 2024
1 parent 3759c7e commit d0aa081
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@
'use strict';

let React;
let ReactDOM;
let ReactDOMClient;
let act;

describe('ReactErrorBoundariesHooks', () => {
beforeEach(() => {
jest.resetModules();
ReactDOM = require('react-dom');
React = require('react');
ReactDOMClient = require('react-dom/client');
act = require('internal-test-utils').act;
});

it('should preserve hook order if errors are caught', () => {
it('should preserve hook order if errors are caught', async () => {
function ErrorThrower() {
React.useMemo(() => undefined, []);
throw new Error('expected');
Expand Down Expand Up @@ -57,10 +59,15 @@ describe('ReactErrorBoundariesHooks', () => {
}

const container = document.createElement('div');
ReactDOM.render(<App />, container);
const root = ReactDOMClient.createRoot(container);
await act(() => {
root.render(<App />);
});

expect(() => {
ReactDOM.render(<App />, container);
}).not.toThrow();
await expect(
act(() => {
root.render(<App />);
}),
).resolves.not.toThrow();
});
});

0 comments on commit d0aa081

Please sign in to comment.