Skip to content

Commit

Permalink
Remove remaining usages of ReactTestUtils in tests unrelated to `reac…
Browse files Browse the repository at this point in the history
…t-dom/test-util` (facebook#28534)

Batched the remaining usages since these were straight forward.
Completes removal of `ReactTestUtils` from tests unrelated to
`react-dom/test-util` together with:
- facebook#28531
- facebook#28532
- facebook#28533
  • Loading branch information
eps1lon authored and AndyPengc12 committed Apr 15, 2024
1 parent feaaccc commit 32c315c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1237,12 +1237,14 @@ describe('ProfilingCache', () => {
);
}

const {Simulate} = require('react-dom/test-utils');

utils.act(() => render(<App />));
expect(getContainer().textContent).toBe('Home');
utils.act(() => store.profilerStore.startProfiling());
utils.act(() => Simulate.click(linkRef.current));
utils.act(() =>
linkRef.current.dispatchEvent(
new MouseEvent('click', {bubbles: true, cancelable: true}),
),
);
utils.act(() => store.profilerStore.stopProfiling());
expect(getContainer().textContent).toBe('About');
});
Expand Down
7 changes: 4 additions & 3 deletions packages/react-dom/src/__tests__/ReactLegacyMount-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const {COMMENT_NODE} = require('react-dom-bindings/src/client/HTMLNodeType');
let React;
let ReactDOM;
let ReactDOMServer;
let ReactTestUtils;
let Scheduler;
let ReactDOMClient;
let assertLog;
Expand All @@ -28,7 +27,6 @@ describe('ReactMount', () => {
ReactDOM = require('react-dom');
ReactDOMClient = require('react-dom/client');
ReactDOMServer = require('react-dom/server');
ReactTestUtils = require('react-dom/test-utils');
Scheduler = require('scheduler');

const InternalTestUtils = require('internal-test-utils');
Expand Down Expand Up @@ -71,7 +69,10 @@ describe('ReactMount', () => {
}
}

expect(() => ReactTestUtils.renderIntoDocument(Component)).toErrorDev(
expect(() => {
const container = document.createElement('div');
ReactDOM.render(Component, container);
}).toErrorDev(
'Functions are not valid as a React child. ' +
'This may happen if you return Component instead of <Component /> from render. ' +
'Or maybe you meant to call this function rather than return it.\n' +
Expand Down
18 changes: 13 additions & 5 deletions packages/react-dom/src/__tests__/findDOMNode-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

const React = require('react');
const ReactDOM = require('react-dom');
const ReactTestUtils = require('react-dom/test-utils');
const StrictMode = React.StrictMode;

describe('findDOMNode', () => {
Expand All @@ -31,7 +30,8 @@ describe('findDOMNode', () => {
}
}

const myNode = ReactTestUtils.renderIntoDocument(<MyNode />);
const container = document.createElement('div');
const myNode = ReactDOM.render(<MyNode />, container);
const myDiv = ReactDOM.findDOMNode(myNode);
const mySameDiv = ReactDOM.findDOMNode(myDiv);
expect(myDiv.tagName).toBe('DIV');
Expand Down Expand Up @@ -99,7 +99,10 @@ describe('findDOMNode', () => {
return <div />;
}
}
expect(() => ReactTestUtils.renderIntoDocument(<Bar />)).not.toThrow();
expect(() => {
const container = document.createElement('div');
ReactDOM.render(<Bar />, container);
}).not.toThrow();
});

// @gate !disableLegacyMode
Expand All @@ -117,8 +120,10 @@ describe('findDOMNode', () => {
}
}

ReactTestUtils.renderIntoDocument(
const container = document.createElement('div');
ReactDOM.render(
<ContainsStrictModeChild ref={n => (parent = n)} />,
container,
);

let match;
Expand All @@ -145,10 +150,13 @@ describe('findDOMNode', () => {
}
}

ReactTestUtils.renderIntoDocument(
const container = document.createElement('div');

ReactDOM.render(
<StrictMode>
<IsInStrictMode ref={n => (parent = n)} />
</StrictMode>,
container,
);

let match;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const React = require('react');
const PropTypes = require('prop-types');
const ReactDOM = require('react-dom');
const ReactDOMClient = require('react-dom/client');
const ReactTestUtils = require('react-dom/test-utils');
const act = require('internal-test-utils').act;
const renderSubtreeIntoContainer =
require('react-dom').unstable_renderSubtreeIntoContainer;
Expand Down Expand Up @@ -60,7 +59,8 @@ describe('renderSubtreeIntoContainer', () => {
}
}

ReactTestUtils.renderIntoDocument(<Parent />);
const container = document.createElement('div');
ReactDOM.render(<Parent />, container);
expect(portal.firstChild.innerHTML).toBe('bar');
});

Expand Down
1 change: 0 additions & 1 deletion packages/react/src/__tests__/ReactTypeScriptClass-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import React = require('react');
import ReactDOM = require('react-dom');
import ReactDOMClient = require('react-dom/client');
import ReactDOMTestUtils = require('react-dom/test-utils');
import PropTypes = require('prop-types');
import ReactFeatureFlags = require('shared/ReactFeatureFlags');

Expand Down

0 comments on commit 32c315c

Please sign in to comment.