Skip to content

Commit

Permalink
Convert ReactErrorBoundariesHooks to createRoot
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Silbermann committed Jan 31, 2024
1 parent d29f7d9 commit b32b4c3
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 b32b4c3

Please sign in to comment.