Skip to content

Commit 00aab3a

Browse files
author
Sebastian Silbermann
committed
Add tests for createRoot
1 parent 91e3800 commit 00aab3a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

packages/react-dom/src/__tests__/ReactDOMRoot-test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ describe('ReactDOMRoot', () => {
133133
expect(container.textContent).toEqual('');
134134
});
135135

136+
it('can be immediately unmounted', async () => {
137+
const root = ReactDOMClient.createRoot(container);
138+
await act(() => {
139+
root.unmount();
140+
});
141+
});
142+
136143
it('supports hydration', async () => {
137144
const markup = await new Promise(resolve =>
138145
resolve(
@@ -392,6 +399,18 @@ describe('ReactDOMRoot', () => {
392399
}
393400
});
394401

402+
it('throws if unmounting a root that has had its contents removed', async () => {
403+
const root = ReactDOMClient.createRoot(container);
404+
await act(() => {
405+
root.render(<div>Hi</div>);
406+
});
407+
container.innerHTML = '';
408+
409+
expect(() => {
410+
root.unmount();
411+
}).toThrow('The node to be removed is not a child of this node.');
412+
});
413+
395414
it('opts-in to concurrent default updates', async () => {
396415
const root = ReactDOMClient.createRoot(container, {
397416
unstable_concurrentUpdatesByDefault: true,

0 commit comments

Comments
 (0)