Skip to content

Commit e40893d

Browse files
authored
add tests for resource emission when rendering no head or just a head (#25433)
1 parent 792343d commit e40893d

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,60 @@ describe('ReactDOMFloat', () => {
248248
);
249249
});
250250

251+
// @gate enableFloat
252+
it('emits resources before everything else when rendering with no head', async () => {
253+
function App() {
254+
return (
255+
<>
256+
<title>foo</title>
257+
<link rel="preload" href="foo" as="style" />
258+
</>
259+
);
260+
}
261+
262+
await actIntoEmptyDocument(() => {
263+
buffer = `<!DOCTYPE html><html><head>${ReactDOMFizzServer.renderToString(
264+
<App />,
265+
)}</head><body>foo</body></html>`;
266+
});
267+
expect(getVisibleChildren(document)).toEqual(
268+
<html>
269+
<head>
270+
<link rel="preload" href="foo" as="style" />
271+
<title>foo</title>
272+
</head>
273+
<body>foo</body>
274+
</html>,
275+
);
276+
});
277+
278+
// @gate enableFloat
279+
it('emits resources before everything else when rendering with just a head', async () => {
280+
function App() {
281+
return (
282+
<head>
283+
<title>foo</title>
284+
<link rel="preload" href="foo" as="style" />
285+
</head>
286+
);
287+
}
288+
289+
await actIntoEmptyDocument(() => {
290+
buffer = `<!DOCTYPE html><html>${ReactDOMFizzServer.renderToString(
291+
<App />,
292+
)}<body>foo</body></html>`;
293+
});
294+
expect(getVisibleChildren(document)).toEqual(
295+
<html>
296+
<head>
297+
<link rel="preload" href="foo" as="style" />
298+
<title>foo</title>
299+
</head>
300+
<body>foo</body>
301+
</html>,
302+
);
303+
});
304+
251305
describe('HostResource', () => {
252306
// @gate enableFloat
253307
it('warns when you update props to an invalid type', async () => {

0 commit comments

Comments
 (0)