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

Remove ReactTestUtils from ReactIdentity #28332

Merged
merged 1 commit into from
Feb 15, 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
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