From cd00293eb78afe7ab0330b32378c86afa76f45d7 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Fri, 26 Jan 2024 10:20:26 +0100 Subject: [PATCH] Convert ChangeEventPlugin to createRoot (#28090) --- .../__tests__/ChangeEventPlugin-test.js | 214 +++++++++++------- 1 file changed, 134 insertions(+), 80 deletions(-) diff --git a/packages/react-dom/src/events/plugins/__tests__/ChangeEventPlugin-test.js b/packages/react-dom/src/events/plugins/__tests__/ChangeEventPlugin-test.js index ae27973a0c603..fab10a36e16d1 100644 --- a/packages/react-dom/src/events/plugins/__tests__/ChangeEventPlugin-test.js +++ b/packages/react-dom/src/events/plugins/__tests__/ChangeEventPlugin-test.js @@ -83,7 +83,7 @@ describe('ChangeEventPlugin', () => { // keep track of the "current" value and only fire events when it changes. // See https://github.com/facebook/react/pull/5746. - it('should consider initial text value to be current', () => { + it('should consider initial text value to be current', async () => { let called = 0; function cb(e) { @@ -91,10 +91,12 @@ describe('ChangeEventPlugin', () => { expect(e.type).toBe('change'); } - const node = ReactDOM.render( - , - container, - ); + const root = ReactDOMClient.createRoot(container); + await act(() => { + root.render(); + }); + + const node = container.firstChild; node.dispatchEvent(new Event('input', {bubbles: true, cancelable: true})); node.dispatchEvent(new Event('change', {bubbles: true, cancelable: true})); @@ -102,7 +104,7 @@ describe('ChangeEventPlugin', () => { expect(called).toBe(0); }); - it('should consider initial text value to be current (capture)', () => { + it('should consider initial text value to be current (capture)', async () => { let called = 0; function cb(e) { @@ -110,10 +112,14 @@ describe('ChangeEventPlugin', () => { expect(e.type).toBe('change'); } - const node = ReactDOM.render( - , - container, - ); + const root = ReactDOMClient.createRoot(container); + await act(() => { + root.render( + , + ); + }); + + const node = container.firstChild; node.dispatchEvent(new Event('input', {bubbles: true, cancelable: true})); node.dispatchEvent(new Event('change', {bubbles: true, cancelable: true})); @@ -121,7 +127,7 @@ describe('ChangeEventPlugin', () => { expect(called).toBe(0); }); - it('should not invoke a change event for textarea same value', () => { + it('should not invoke a change event for textarea same value', async () => { let called = 0; function cb(e) { @@ -129,17 +135,19 @@ describe('ChangeEventPlugin', () => { expect(e.type).toBe('change'); } - const node = ReactDOM.render( -