diff --git a/packages/react-dom/src/__tests__/ReactDOMComponent-test.js b/packages/react-dom/src/__tests__/ReactDOMComponent-test.js index 3ee19c72e2e09..f904d372052aa 100644 --- a/packages/react-dom/src/__tests__/ReactDOMComponent-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMComponent-test.js @@ -13,15 +13,20 @@ describe('ReactDOMComponent', () => { let React; let ReactTestUtils; let ReactDOM; + let ReactDOMClient; let ReactDOMServer; const ReactFeatureFlags = require('shared/ReactFeatureFlags'); + let act; + beforeEach(() => { jest.resetModules(); React = require('react'); ReactDOM = require('react-dom'); + ReactDOMClient = require('react-dom/client'); ReactDOMServer = require('react-dom/server'); ReactTestUtils = require('react-dom/test-utils'); + act = require('internal-test-utils').act; }); afterEach(() => { @@ -29,21 +34,33 @@ describe('ReactDOMComponent', () => { }); describe('updateDOM', () => { - it('should handle className', () => { + it('should handle className', async () => { const container = document.createElement('div'); - ReactDOM.render(
, container); + const root = ReactDOMClient.createRoot(container); + await act(() => { + root.render(); + }); - ReactDOM.render(, container); + await act(() => { + root.render(); + }); expect(container.firstChild.className).toEqual('foo'); - ReactDOM.render(, container); + await act(() => { + root.render(); + }); expect(container.firstChild.className).toEqual('bar'); - ReactDOM.render(, container); + await act(() => { + root.render(); + }); expect(container.firstChild.className).toEqual(''); }); - it('should gracefully handle various style value types', () => { + it('should gracefully handle various style value types', async () => { const container = document.createElement('div'); - ReactDOM.render(, container); + const root = ReactDOMClient.createRoot(container); + await act(() => { + root.render(); + }); const stubStyle = container.firstChild.style; // set initial style @@ -53,7 +70,9 @@ describe('ReactDOMComponent', () => { top: 2, fontFamily: 'Arial', }; - ReactDOM.render(, container); + await act(() => { + root.render(); + }); expect(stubStyle.display).toEqual('block'); expect(stubStyle.left).toEqual('1px'); expect(stubStyle.top).toEqual('2px'); @@ -61,14 +80,16 @@ describe('ReactDOMComponent', () => { // reset the style to their default state const reset = {display: '', left: null, top: false, fontFamily: true}; - ReactDOM.render(, container); + await act(() => { + root.render(); + }); expect(stubStyle.display).toEqual(''); expect(stubStyle.left).toEqual(''); expect(stubStyle.top).toEqual(''); expect(stubStyle.fontFamily).toEqual(''); }); - it('should not update styles when mutating a proxy style object', () => { + it('should not update styles when mutating a proxy style object', async () => { const styleStore = { display: 'none', fontFamily: 'Arial', @@ -97,7 +118,10 @@ describe('ReactDOMComponent', () => { }, }; const container = document.createElement('div'); - ReactDOM.render(, container); + const root = ReactDOMClient.createRoot(container); + await act(() => { + root.render(); + }); const stubStyle = container.firstChild.style; stubStyle.display = styles.display; @@ -105,26 +129,34 @@ describe('ReactDOMComponent', () => { styles.display = 'block'; - ReactDOM.render(, container); + await act(() => { + root.render(); + }); expect(stubStyle.display).toEqual('none'); expect(stubStyle.fontFamily).toEqual('Arial'); expect(stubStyle.lineHeight).toEqual('1.2'); styles.fontFamily = 'Helvetica'; - ReactDOM.render(, container); + await act(() => { + root.render(); + }); expect(stubStyle.display).toEqual('none'); expect(stubStyle.fontFamily).toEqual('Arial'); expect(stubStyle.lineHeight).toEqual('1.2'); styles.lineHeight = 0.5; - ReactDOM.render(, container); + await act(() => { + root.render(); + }); expect(stubStyle.display).toEqual('none'); expect(stubStyle.fontFamily).toEqual('Arial'); expect(stubStyle.lineHeight).toEqual('1.2'); - ReactDOM.render(, container); + await act(() => { + root.render(); + }); expect(stubStyle.display).toBe(''); expect(stubStyle.fontFamily).toBe(''); expect(stubStyle.lineHeight).toBe(''); @@ -147,11 +179,14 @@ describe('ReactDOMComponent', () => { } }); - it('should warn for unknown prop', () => { + it('should warn for unknown prop', async () => { const container = document.createElement('div'); - expect(() => - ReactDOM.render(