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 ReactJSXTransformIntegration #28338

Merged
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
28 changes: 19 additions & 9 deletions packages/react/src/__tests__/ReactJSXTransformIntegration-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

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

// TODO: Historically this module was used to confirm that the JSX transform
Expand All @@ -30,7 +29,6 @@ describe('ReactJSXTransformIntegration', () => {

React = require('react');
ReactDOMClient = require('react-dom/client');
ReactTestUtils = require('react-dom/test-utils');
act = require('internal-test-utils').act;

Component = class extends React.Component {
Expand Down Expand Up @@ -213,22 +211,34 @@ describe('ReactJSXTransformIntegration', () => {
expect(instance.props.fruit).toBe('persimmon');
});

it('should normalize props with default values', () => {
it('should normalize props with default values', async () => {
class NormalizingComponent extends React.Component {
render() {
return <span>{this.props.prop}</span>;
}
}
NormalizingComponent.defaultProps = {prop: 'testKey'};

const instance = ReactTestUtils.renderIntoDocument(
<NormalizingComponent />,
);
let container = document.createElement('div');
let root = ReactDOMClient.createRoot(container);
let instance;
await act(() => {
root.render(
<NormalizingComponent ref={current => (instance = current)} />,
);
});

expect(instance.props.prop).toBe('testKey');

const inst2 = ReactTestUtils.renderIntoDocument(
<NormalizingComponent prop={null} />,
);
container = document.createElement('div');
root = ReactDOMClient.createRoot(container);
let inst2;
await act(() => {
root.render(
<NormalizingComponent prop={null} ref={current => (inst2 = current)} />,
);
});

expect(inst2.props.prop).toBe(null);
});
});