Skip to content

Commit 093ad1c

Browse files
kassensAndyPengc12
authored andcommitted
Convert ReactServerRenderingHydration-test to createRoot (partially) (facebook#28010)
Convert ReactServerRenderingHydration-test to createRoot (partially) Some tests seem to be specifically testing the legacy APIs, maybe we need to keep those around. Keeping this PR to the simple updates.
1 parent 50bba42 commit 093ad1c

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

packages/react-dom/src/__tests__/ReactServerRenderingHydration-test.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ describe('ReactDOMServerHydration', () => {
122122
// We have a polyfill for autoFocus on the client, but we intentionally don't
123123
// want it to call focus() when hydrating because this can mess up existing
124124
// focus before the JS has loaded.
125-
it('should emit autofocus on the server but not focus() when hydrating', () => {
125+
it('should emit autofocus on the server but not focus() when hydrating', async () => {
126126
const element = document.createElement('div');
127127
element.innerHTML = ReactDOMServer.renderToString(
128128
<input autoFocus={true} />,
@@ -131,26 +131,35 @@ describe('ReactDOMServerHydration', () => {
131131

132132
// It should not be called on mount.
133133
element.firstChild.focus = jest.fn();
134-
ReactDOM.hydrate(<input autoFocus={true} />, element);
134+
const root = await act(() =>
135+
ReactDOMClient.hydrateRoot(element, <input autoFocus={true} />),
136+
);
135137
expect(element.firstChild.focus).not.toHaveBeenCalled();
136138

137139
// Or during an update.
138-
ReactDOM.render(<input autoFocus={true} />, element);
140+
await act(() => {
141+
root.render(<input autoFocus={true} />);
142+
});
139143
expect(element.firstChild.focus).not.toHaveBeenCalled();
140144
});
141145

142-
it('should not focus on either server or client with autofocus={false}', () => {
146+
it('should not focus on either server or client with autofocus={false}', async () => {
143147
const element = document.createElement('div');
144148
element.innerHTML = ReactDOMServer.renderToString(
145149
<input autoFocus={false} />,
146150
);
147151
expect(element.firstChild.autofocus).toBe(false);
148152

149153
element.firstChild.focus = jest.fn();
150-
ReactDOM.hydrate(<input autoFocus={false} />, element);
154+
const root = await act(() =>
155+
ReactDOMClient.hydrateRoot(element, <input autoFocus={false} />),
156+
);
157+
151158
expect(element.firstChild.focus).not.toHaveBeenCalled();
152159

153-
ReactDOM.render(<input autoFocus={false} />, element);
160+
await act(() => {
161+
root.render(<input autoFocus={false} />);
162+
});
154163
expect(element.firstChild.focus).not.toHaveBeenCalled();
155164
});
156165

0 commit comments

Comments
 (0)