diff --git a/packages/react-dom/src/__tests__/ReactDOMComponentTree-test.js b/packages/react-dom/src/__tests__/ReactDOMComponentTree-test.js
index 12d34a34a4ea3..ffaae4f699a60 100644
--- a/packages/react-dom/src/__tests__/ReactDOMComponentTree-test.js
+++ b/packages/react-dom/src/__tests__/ReactDOMComponentTree-test.js
@@ -11,12 +11,15 @@
describe('ReactDOMComponentTree', () => {
let React;
- let ReactDOM;
+ let ReactDOMClient;
+ let act;
let container;
beforeEach(() => {
React = require('react');
- ReactDOM = require('react-dom');
+ ReactDOMClient = require('react-dom/client');
+ act = require('internal-test-utils').act;
+
container = document.createElement('div');
document.body.appendChild(container);
});
@@ -26,7 +29,7 @@ describe('ReactDOMComponentTree', () => {
container = null;
});
- it('finds nodes for instances on events', () => {
+ it('finds nodes for instances on events', async () => {
const mouseOverID = 'mouseOverID';
const clickID = 'clickID';
let currentTargetID = null;
@@ -34,17 +37,16 @@ describe('ReactDOMComponentTree', () => {
// when an event is dispatched so we can test behavior by invoking
// events on elements in the tree and confirming the expected node is
// set as the current target
- class Component extends React.Component {
- handler = e => {
+ function Component() {
+ const handler = e => {
currentTargetID = e.currentTarget.id;
};
- render() {
- return (
-
, container);
- expect(() => ReactDOM.unmountComponentAtNode(node)).toErrorDev(
- "unmountComponentAtNode(): The node you're attempting to unmount " +
- 'was rendered by React and is not a top-level container. You may ' +
- 'have accidentally passed in a React root node instead of its ' +
- 'container.',
- {withoutStack: true},
- );
- });
-
- it('finds instance from node to stop rendering over other react rendered components', () => {
- const component = (
-
- Hello
-
- );
- const anotherComponent = ;
- const instance = ReactDOM.render(component, container);
- expect(() => ReactDOM.render(anotherComponent, instance)).toErrorDev(
- 'render(...): Replacing React-rendered children with a new root ' +
- 'component. If you intended to update the children of this node, ' +
- 'you should instead have the existing children update their state ' +
- 'and render the new components instead of calling ReactDOM.render.',
- {withoutStack: true},
- );
- });
});
diff --git a/packages/react-dom/src/__tests__/ReactDOMLegacyComponentTree-test.internal.js b/packages/react-dom/src/__tests__/ReactDOMLegacyComponentTree-test.internal.js
new file mode 100644
index 0000000000000..de9f79ff23529
--- /dev/null
+++ b/packages/react-dom/src/__tests__/ReactDOMLegacyComponentTree-test.internal.js
@@ -0,0 +1,58 @@
+/**
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
+ *
+ * This source code is licensed under the MIT license found in the
+ * LICENSE file in the root directory of this source tree.
+ *
+ * @emails react-core
+ */
+
+'use strict';
+
+describe('ReactDOMComponentTree', () => {
+ let React;
+ let ReactDOM;
+ let container;
+
+ beforeEach(() => {
+ React = require('react');
+ ReactDOM = require('react-dom');
+
+ container = document.createElement('div');
+ document.body.appendChild(container);
+ });
+
+ afterEach(() => {
+ document.body.removeChild(container);
+ container = null;
+ });
+
+ it('finds instance of node that is attempted to be unmounted', () => {
+ const component = ;
+ const node = ReactDOM.render(
{component}
, container);
+ expect(() => ReactDOM.unmountComponentAtNode(node)).toErrorDev(
+ "unmountComponentAtNode(): The node you're attempting to unmount " +
+ 'was rendered by React and is not a top-level container. You may ' +
+ 'have accidentally passed in a React root node instead of its ' +
+ 'container.',
+ {withoutStack: true},
+ );
+ });
+
+ it('finds instance from node to stop rendering over other react rendered components', () => {
+ const component = (
+
+ Hello
+
+ );
+ const anotherComponent = ;
+ const instance = ReactDOM.render(component, container);
+ expect(() => ReactDOM.render(anotherComponent, instance)).toErrorDev(
+ 'render(...): Replacing React-rendered children with a new root ' +
+ 'component. If you intended to update the children of this node, ' +
+ 'you should instead have the existing children update their state ' +
+ 'and render the new components instead of calling ReactDOM.render.',
+ {withoutStack: true},
+ );
+ });
+});