add tests for resource emission when rendering no head or just a head (#25433)
Josh Story committed
Oct 5, 2022 at 10:14 UTC
e40893d097f6894b4768d749f796302c57161734
1 file changed
+54
packages/react-dom/src/__tests__/ReactDOMFloat-test.js
+54
@@ -248,6 +248,60 @@ describe('ReactDOMFloat', () => {
248
);
249
});
250
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
+
305
describe('HostResource', () => {
306
// @gate enableFloat
307
it('warns when you update props to an invalid type', async () => {