forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use createRoot in ReactDOMComponentTree-test (facebook#28112)
- Loading branch information
1 parent
25ed06e
commit 6f857fd
Showing
2 changed files
with
145 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
packages/react-dom/src/__tests__/ReactDOMLegacyComponentTree-test.internal.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 = <div />; | ||
const node = ReactDOM.render(<div>{component}</div>, 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 = ( | ||
<div> | ||
<span>Hello</span> | ||
</div> | ||
); | ||
const anotherComponent = <div />; | ||
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}, | ||
); | ||
}); | ||
}); |