Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use versioned render in useEditableValue test #28212

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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