Skip to content

Commit

Permalink
Remove ReactTestUtils from ReactIdentity (facebook#28332)
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon authored and AndyPengc12 committed Apr 15, 2024
1 parent 425ff2e commit 836a025
Showing 1 changed file with 32 additions and 18 deletions.
50 changes: 32 additions & 18 deletions packages/react-dom/src/__tests__/ReactIdentity-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@

let React;
let ReactDOMClient;
let ReactTestUtils;
let act;

describe('ReactIdentity', () => {
beforeEach(() => {
jest.resetModules();
React = require('react');
ReactDOMClient = require('react-dom/client');
ReactTestUtils = require('react-dom/test-utils');
act = require('internal-test-utils').act;
});

Expand Down Expand Up @@ -127,7 +125,7 @@ describe('ReactIdentity', () => {
expect(window.YOUVEBEENH4X0RED).toBe(undefined);
});

it('should let restructured components retain their uniqueness', () => {
it('should let restructured components retain their uniqueness', async () => {
const instance0 = <span />;
const instance1 = <span />;
const instance2 = <span />;
Expand Down Expand Up @@ -155,12 +153,16 @@ describe('ReactIdentity', () => {
}
}

expect(function () {
ReactTestUtils.renderIntoDocument(<TestContainer />);
}).not.toThrow();
const container = document.createElement('div');
const root = ReactDOMClient.createRoot(container);
await expect(
act(() => {
root.render(<TestContainer />);
}),
).resolves.not.toThrow();
});

it('should let nested restructures retain their uniqueness', () => {
it('should let nested restructures retain their uniqueness', async () => {
const instance0 = <span />;
const instance1 = <span />;
const instance2 = <span />;
Expand Down Expand Up @@ -190,12 +192,16 @@ describe('ReactIdentity', () => {
}
}

expect(function () {
ReactTestUtils.renderIntoDocument(<TestContainer />);
}).not.toThrow();
const container = document.createElement('div');
const root = ReactDOMClient.createRoot(container);
await expect(
act(() => {
root.render(<TestContainer />);
}),
).resolves.not.toThrow();
});

it('should let text nodes retain their uniqueness', () => {
it('should let text nodes retain their uniqueness', async () => {
class TestComponent extends React.Component {
render() {
return (
Expand All @@ -218,9 +224,13 @@ describe('ReactIdentity', () => {
}
}

expect(function () {
ReactTestUtils.renderIntoDocument(<TestContainer />);
}).not.toThrow();
const container = document.createElement('div');
const root = ReactDOMClient.createRoot(container);
await expect(
act(() => {
root.render(<TestContainer />);
}),
).resolves.not.toThrow();
});

it('should retain key during updates in composite components', async () => {
Expand Down Expand Up @@ -272,17 +282,21 @@ describe('ReactIdentity', () => {
expect(beforeB).toBe(afterB);
});

it('should not allow implicit and explicit keys to collide', () => {
it('should not allow implicit and explicit keys to collide', async () => {
const component = (
<div>
<span />
<span key="0" />
</div>
);

expect(function () {
ReactTestUtils.renderIntoDocument(component);
}).not.toThrow();
const container = document.createElement('div');
const root = ReactDOMClient.createRoot(container);
await expect(
act(() => {
root.render(component);
}),
).resolves.not.toThrow();
});

it('should throw if key is a Temporal-like object', async () => {
Expand Down

0 comments on commit 836a025

Please sign in to comment.