Skip to content

Commit

Permalink
Add test for the warning
Browse files Browse the repository at this point in the history
  • Loading branch information
sebmarkbage committed Feb 28, 2022
1 parent abc6824 commit ecedff2
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/react-dom/src/__tests__/ReactDOMRoot-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,26 @@ describe('ReactDOMRoot', () => {
expect(container.textContent).toEqual('Hi');
});

it('warns if you import createRoot from react-dom', async () => {
expect(() => ReactDOM.createRoot(container)).toErrorDev(
'You are importing createRoot from "react-dom" which is not supported. ' +
'You should instead import it from "react-dom/client".',
{
withoutStack: true,
},
);
});

it('warns if you import hydrateRoot from react-dom', async () => {
expect(() => ReactDOM.hydrateRoot(container, null)).toErrorDev(
'You are importing hydrateRoot from "react-dom" which is not supported. ' +
'You should instead import it from "react-dom/client".',
{
withoutStack: true,
},
);
});

it('warns if a callback parameter is provided to render', () => {
const callback = jest.fn();
const root = ReactDOMClient.createRoot(container);
Expand Down

0 comments on commit ecedff2

Please sign in to comment.