diff --git a/packages/react-dom/src/__tests__/ReactServerRenderingHydration-test.js b/packages/react-dom/src/__tests__/ReactServerRenderingHydration-test.js
index f574b16040b68..c7416b255d471 100644
--- a/packages/react-dom/src/__tests__/ReactServerRenderingHydration-test.js
+++ b/packages/react-dom/src/__tests__/ReactServerRenderingHydration-test.js
@@ -122,7 +122,7 @@ describe('ReactDOMServerHydration', () => {
// We have a polyfill for autoFocus on the client, but we intentionally don't
// want it to call focus() when hydrating because this can mess up existing
// focus before the JS has loaded.
- it('should emit autofocus on the server but not focus() when hydrating', () => {
+ it('should emit autofocus on the server but not focus() when hydrating', async () => {
const element = document.createElement('div');
element.innerHTML = ReactDOMServer.renderToString(
,
@@ -131,15 +131,19 @@ describe('ReactDOMServerHydration', () => {
// It should not be called on mount.
element.firstChild.focus = jest.fn();
- ReactDOM.hydrate(, element);
+ const root = await act(() =>
+ ReactDOMClient.hydrateRoot(element, ),
+ );
expect(element.firstChild.focus).not.toHaveBeenCalled();
// Or during an update.
- ReactDOM.render(, element);
+ await act(() => {
+ root.render();
+ });
expect(element.firstChild.focus).not.toHaveBeenCalled();
});
- it('should not focus on either server or client with autofocus={false}', () => {
+ it('should not focus on either server or client with autofocus={false}', async () => {
const element = document.createElement('div');
element.innerHTML = ReactDOMServer.renderToString(
,
@@ -147,10 +151,15 @@ describe('ReactDOMServerHydration', () => {
expect(element.firstChild.autofocus).toBe(false);
element.firstChild.focus = jest.fn();
- ReactDOM.hydrate(, element);
+ const root = await act(() =>
+ ReactDOMClient.hydrateRoot(element, ),
+ );
+
expect(element.firstChild.focus).not.toHaveBeenCalled();
- ReactDOM.render(, element);
+ await act(() => {
+ root.render();
+ });
expect(element.firstChild.focus).not.toHaveBeenCalled();
});