Skip to content

Commit

Permalink
Convert ReactMultiChildText to createRoot (#28140)
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon authored and gaearon committed Feb 3, 2024
1 parent d0d982d commit 3e90785
Showing 1 changed file with 56 additions and 36 deletions.
92 changes: 56 additions & 36 deletions packages/react-dom/src/__tests__/ReactMultiChildText-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

const React = require('react');
const ReactDOMClient = require('react-dom/client');
const ReactTestUtils = require('react-dom/test-utils');
const act = require('internal-test-utils').act;

// Helpers
Expand Down Expand Up @@ -174,46 +173,67 @@ describe('ReactMultiChildText', () => {
]);
});

it('should throw if rendering both HTML and children', () => {
expect(function () {
ReactTestUtils.renderIntoDocument(
<div dangerouslySetInnerHTML={{__html: 'abcdef'}}>ghjkl</div>,
);
}).toThrow();
it('should throw if rendering both HTML and children', async () => {
const container = document.createElement('div');
const root = ReactDOMClient.createRoot(container);
await expect(
act(() => {
root.render(
<div dangerouslySetInnerHTML={{__html: 'abcdef'}}>ghjkl</div>,
);
}),
).rejects.toThrow();
});

it('should render between nested components and inline children', () => {
ReactTestUtils.renderIntoDocument(
<div>
<h1>
<span />
<span />
</h1>
</div>,
);

expect(function () {
ReactTestUtils.renderIntoDocument(
<div>
<h1>A</h1>
</div>,
);
}).not.toThrow();

expect(function () {
ReactTestUtils.renderIntoDocument(
<div>
<h1>{['A']}</h1>
</div>,
);
}).not.toThrow();
it('should render between nested components and inline children', async () => {
let container = document.createElement('div');
let root = ReactDOMClient.createRoot(container);

expect(function () {
ReactTestUtils.renderIntoDocument(
await act(() => {
root.render(
<div>
<h1>{['A', 'B']}</h1>
<h1>
<span />
<span />
</h1>
</div>,
);
}).not.toThrow();
});

container = document.createElement('div');
root = ReactDOMClient.createRoot(container);
await expect(
act(() => {
root.render(
<div>
<h1>A</h1>
</div>,
);
}),
).resolves.not.toThrow();

container = document.createElement('div');
root = ReactDOMClient.createRoot(container);
await expect(
act(() => {
root.render(
<div>
<h1>{['A']}</h1>
</div>,
);
}),
).resolves.not.toThrow();

container = document.createElement('div');
root = ReactDOMClient.createRoot(container);
await expect(
act(() => {
root.render(
<div>
<h1>{['A', 'B']}</h1>
</div>,
);
}),
).resolves.not.toThrow();
});
});

0 comments on commit 3e90785

Please sign in to comment.