From 40627941d089963633293e2b49af2a9d857099c7 Mon Sep 17 00:00:00 2001 From: Ruslan Lesiutin Date: Fri, 2 Feb 2024 16:36:10 +0000 Subject: [PATCH] chore: use versioned render in useEditableValue test --- .../src/__tests__/useEditableValue-test.js | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/packages/react-devtools-shared/src/__tests__/useEditableValue-test.js b/packages/react-devtools-shared/src/__tests__/useEditableValue-test.js index d3ae11df7999f..61b538e2d2e6f 100644 --- a/packages/react-devtools-shared/src/__tests__/useEditableValue-test.js +++ b/packages/react-devtools-shared/src/__tests__/useEditableValue-test.js @@ -7,22 +7,24 @@ * @flow */ +import {getVersionedRenderImplementation} from './utils'; + describe('useEditableValue', () => { let act; let React; - let legacyRender; let useEditableValue; beforeEach(() => { const utils = require('./utils'); act = utils.act; - legacyRender = utils.legacyRender; React = require('react'); useEditableValue = require('../devtools/views/hooks').useEditableValue; }); + const {render} = getVersionedRenderImplementation(); + it('should not cause a loop with values like NaN', () => { let state; @@ -32,8 +34,8 @@ describe('useEditableValue', () => { return null; } - const container = document.createElement('div'); - legacyRender(, container); + act(() => render()); + expect(state.editableValue).toEqual('NaN'); expect(state.externalValue).toEqual(NaN); expect(state.parsedValue).toEqual(NaN); @@ -50,8 +52,8 @@ describe('useEditableValue', () => { return null; } - const container = document.createElement('div'); - legacyRender(, container); + act(() => render()); + expect(state.editableValue).toEqual('1'); expect(state.externalValue).toEqual(1); expect(state.parsedValue).toEqual(1); @@ -60,7 +62,8 @@ describe('useEditableValue', () => { // If there are NO pending changes, // an update to the external prop value should override the local/pending value. - legacyRender(, container); + act(() => render()); + expect(state.editableValue).toEqual('2'); expect(state.externalValue).toEqual(2); expect(state.parsedValue).toEqual(2); @@ -78,8 +81,8 @@ describe('useEditableValue', () => { return null; } - const container = document.createElement('div'); - legacyRender(, container); + act(() => render()); + expect(state.editableValue).toEqual('1'); expect(state.externalValue).toEqual(1); expect(state.parsedValue).toEqual(1); @@ -102,7 +105,8 @@ describe('useEditableValue', () => { // If there ARE pending changes, // an update to the external prop value should NOT override the local/pending value. - legacyRender(, container); + act(() => render()); + expect(state.editableValue).toEqual('2'); expect(state.externalValue).toEqual(3); expect(state.parsedValue).toEqual(2); @@ -120,8 +124,8 @@ describe('useEditableValue', () => { return null; } - const container = document.createElement('div'); - legacyRender(, container); + act(() => render()); + expect(state.editableValue).toEqual('1'); expect(state.externalValue).toEqual(1); expect(state.parsedValue).toEqual(1); @@ -153,8 +157,8 @@ describe('useEditableValue', () => { return null; } - const container = document.createElement('div'); - legacyRender(, container); + act(() => render()); + expect(state.editableValue).toEqual('1'); expect(state.externalValue).toEqual(1); expect(state.parsedValue).toEqual(1);