Skip to content

Commit

Permalink
chore: use versioned render in useEditableValue test
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxyq committed Feb 2, 2024
1 parent 631bb9e commit 130ed8d
Showing 1 changed file with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -32,8 +34,8 @@ describe('useEditableValue', () => {
return null;
}

const container = document.createElement('div');
legacyRender(<Example />, container);
act(() => render(<Example />));

expect(state.editableValue).toEqual('NaN');
expect(state.externalValue).toEqual(NaN);
expect(state.parsedValue).toEqual(NaN);
Expand All @@ -50,8 +52,8 @@ describe('useEditableValue', () => {
return null;
}

const container = document.createElement('div');
legacyRender(<Example value={1} />, container);
act(() => render(<Example value={1} />));

expect(state.editableValue).toEqual('1');
expect(state.externalValue).toEqual(1);
expect(state.parsedValue).toEqual(1);
Expand All @@ -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(<Example value={2} />, container);
act(() => render(<Example value={2} />));

expect(state.editableValue).toEqual('2');
expect(state.externalValue).toEqual(2);
expect(state.parsedValue).toEqual(2);
Expand All @@ -78,8 +81,8 @@ describe('useEditableValue', () => {
return null;
}

const container = document.createElement('div');
legacyRender(<Example value={1} />, container);
act(() => render(<Example value={1} />));

expect(state.editableValue).toEqual('1');
expect(state.externalValue).toEqual(1);
expect(state.parsedValue).toEqual(1);
Expand All @@ -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(<Example value={3} />, container);
act(() => render(<Example value={3} />));

expect(state.editableValue).toEqual('2');
expect(state.externalValue).toEqual(3);
expect(state.parsedValue).toEqual(2);
Expand All @@ -120,8 +124,8 @@ describe('useEditableValue', () => {
return null;
}

const container = document.createElement('div');
legacyRender(<Example value={1} />, container);
act(() => render(<Example value={1} />));

expect(state.editableValue).toEqual('1');
expect(state.externalValue).toEqual(1);
expect(state.parsedValue).toEqual(1);
Expand Down Expand Up @@ -153,8 +157,8 @@ describe('useEditableValue', () => {
return null;
}

const container = document.createElement('div');
legacyRender(<Example value={1} />, container);
act(() => render(<Example value={1} />));

expect(state.editableValue).toEqual('1');
expect(state.externalValue).toEqual(1);
expect(state.parsedValue).toEqual(1);
Expand Down

0 comments on commit 130ed8d

Please sign in to comment.