Skip to content

Commit

Permalink
Update test
Browse files Browse the repository at this point in the history
  • Loading branch information
sebmarkbage committed Mar 27, 2024
1 parent 0ad2574 commit f01dd3d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
47 changes: 32 additions & 15 deletions packages/react-dom/src/__tests__/ReactComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,25 @@ describe('ReactComponent', () => {
act = require('internal-test-utils').act;
});

// @gate !disableLegacyMode
// @gate !disableLegacyMode && www
it('should throw on invalid render targets in legacy roots', () => {
const container = document.createElement('div');
// jQuery objects are basically arrays; people often pass them in by mistake
expect(function () {
ReactDOM.render(<div />, [container]);
}).toThrowError(/Target container is not a DOM element./);

expect(function () {
ReactDOM.render(<div />, null);
}).toThrowError(/Target container is not a DOM element./);
expect(() => {
expect(function () {
ReactDOM.render(<div />, [container]);
}).toThrowError(/Target container is not a DOM element./);

expect(function () {
ReactDOM.render(<div />, null);
}).toThrowError(/Target container is not a DOM element./);
}).toErrorDev(
[
'ReactDOM.render is no longer supported in React 18.',
'ReactDOM.render is no longer supported in React 18.',
],
{withoutStack: true},
);
});

// @gate !disableStringRefs
Expand Down Expand Up @@ -456,16 +464,25 @@ describe('ReactComponent', () => {
/* eslint-enable indent */
});

// @gate !disableLegacyMode
// @gate !disableLegacyMode && www
it('fires the callback after a component is rendered in legacy roots', () => {
const callback = jest.fn();
const container = document.createElement('div');
ReactDOM.render(<div />, container, callback);
expect(callback).toHaveBeenCalledTimes(1);
ReactDOM.render(<div className="foo" />, container, callback);
expect(callback).toHaveBeenCalledTimes(2);
ReactDOM.render(<span />, container, callback);
expect(callback).toHaveBeenCalledTimes(3);
expect(() => {
ReactDOM.render(<div />, container, callback);
expect(callback).toHaveBeenCalledTimes(1);
ReactDOM.render(<div className="foo" />, container, callback);
expect(callback).toHaveBeenCalledTimes(2);
ReactDOM.render(<span />, container, callback);
expect(callback).toHaveBeenCalledTimes(3);
}).toErrorDev(
[
'ReactDOM.render is no longer supported in React 18.',
'ReactDOM.render is no longer supported in React 18.',
'ReactDOM.render is no longer supported in React 18.',
],
{withoutStack: true},
);
});

it('throws usefully when rendering badly-typed elements', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ describe('ReactTestRenderer', () => {
null,
expect.anything(),
expect.anything(),
expect.anything(),
expect.anything(),
null,
);
}
Expand Down

0 comments on commit f01dd3d

Please sign in to comment.