From 093ad1c6c7508aad3477a01dac5b512258c842d5 Mon Sep 17 00:00:00 2001 From: Jan Kassens Date: Wed, 24 Jan 2024 10:38:28 -0500 Subject: [PATCH] Convert ReactServerRenderingHydration-test to createRoot (partially) (#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. --- .../ReactServerRenderingHydration-test.js | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) 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(); });