Convert ReactErrorBoundariesHooks to createRoot (#28175)
Sebastian Silbermann committed
Feb 2, 2024 at 00:48 UTC
c39ec17e66552d8ea8d6d3e11c1d7f85a9f7247f
1 file changed
+14
-7
packages/react-dom/src/__tests__/ReactErrorBoundariesHooks-test.internal.js
+14
-7
@@ -10,16 +10,18 @@
10
'use strict';
11
12
let React;
13
-let ReactDOM;
13
+let ReactDOMClient;
14
+let act;
15
16
describe('ReactErrorBoundariesHooks', () => {
17
beforeEach(() => {
18
jest.resetModules();
18
- ReactDOM = require('react-dom');
19
React = require('react');
20
+ ReactDOMClient = require('react-dom/client');
21
+ act = require('internal-test-utils').act;
22
});
23
22
- it('should preserve hook order if errors are caught', () => {
24
+ it('should preserve hook order if errors are caught', async () => {
25
function ErrorThrower() {
26
React.useMemo(() => undefined, []);
27
throw new Error('expected');
@@ -57,10 +59,15 @@ describe('ReactErrorBoundariesHooks', () => {
59
}
60
61
const container = document.createElement('div');
60
- ReactDOM.render(<App />, container);
62
+ const root = ReactDOMClient.createRoot(container);
63
+ await act(() => {
64
+ root.render(<App />);
65
+ });
66
62
- expect(() => {
63
- ReactDOM.render(<App />, container);
64
- }).not.toThrow();
67
+ await expect(
68
+ act(() => {
69
+ root.render(<App />);
70
+ }),
71
+ ).resolves.not.toThrow();
72
});
73
});