Skip to content

Commit

Permalink
fix: move into separate test
Browse files Browse the repository at this point in the history
  • Loading branch information
styfle committed Jul 12, 2023
1 parent 2e38548 commit 24e2703
Showing 1 changed file with 82 additions and 25 deletions.
107 changes: 82 additions & 25 deletions packages/react-dom/src/__tests__/ReactDOMFloat-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3585,13 +3585,6 @@ body {
imageSizes: 'makes no sense',
});

ReactDOM.preload('rp', {
as: 'image',
imageSrcSet: 'rpsrcset',
imageSizes: 'rpsizes',
referrerPolicy: 'no-referrer',
});

if (isClient) {
// Will key off href in absense of imageSrcSet
ReactDOM.preload('client', {as: 'image'});
Expand Down Expand Up @@ -3641,19 +3634,31 @@ body {
imagesizes="foosizes"
/>
<link rel="preload" as="somethingelse" href="bar" />
</head>
<body>hello</body>
</html>,
);

const root = ReactDOMClient.hydrateRoot(document, <App />);
await waitForAll([]);
expect(getMeaningfulChildren(document)).toEqual(
<html>
<head>
<link rel="preload" as="image" href="foo" />
<link rel="preload" as="image" imagesrcset="fooset" />
<link
rel="preload"
as="image"
imagesrcset="rpsrcset"
imagesizes="rpsizes"
referrerpolicy="no-referrer"
imagesrcset="fooset"
imagesizes="foosizes"
/>
<link rel="preload" as="somethingelse" href="bar" />
</head>
<body>hello</body>
</html>,
);

const root = ReactDOMClient.hydrateRoot(document, <App />);
root.render(<App isClient={true} />);
await waitForAll([]);
expect(getMeaningfulChildren(document)).toEqual(
<html>
Expand All @@ -3667,46 +3672,98 @@ body {
imagesizes="foosizes"
/>
<link rel="preload" as="somethingelse" href="bar" />
<link rel="preload" as="image" href="client" />
<link rel="preload" as="image" imagesrcset="clientset" />
<link
rel="preload"
as="image"
imagesrcset="clientset"
imagesizes="clientsizes"
/>
</head>
<body>hello</body>
</html>,
);
});

it('should handle referrerPolicy on image preload', async () => {
function App({isClient}) {
ReactDOM.preload('/server', {
as: 'image',
imageSrcSet: '/server',
imageSizes: '100vw',
referrerPolicy: 'no-referrer',
});

if (isClient) {
ReactDOM.preload('/client', {
as: 'image',
imageSrcSet: '/client',
imageSizes: '100vw',
referrerPolicy: 'no-referrer',
});
}

return (
<html>
<body>hello</body>
</html>
);
}

await act(() => {
renderToPipeableStream(<App />).pipe(writable);
});
expect(getMeaningfulChildren(document)).toEqual(
<html>
<head>
<link
rel="preload"
as="image"
imagesrcset="rpsrcset"
imagesizes="rpsizes"
imagesrcset="/server"
imagesizes="100vw"
referrerpolicy="no-referrer"
/>
</head>
<body>hello</body>
</html>,
);

root.render(<App isClient={true} />);
const root = ReactDOMClient.hydrateRoot(document, <App />);
await waitForAll([]);
expect(getMeaningfulChildren(document)).toEqual(
<html>
<head>
<link rel="preload" as="image" href="foo" />
<link rel="preload" as="image" imagesrcset="fooset" />
<link
rel="preload"
as="image"
imagesrcset="fooset"
imagesizes="foosizes"
imagesrcset="/server"
imagesizes="100vw"
referrerpolicy="no-referrer"
/>
<link rel="preload" as="somethingelse" href="bar" />
</head>
<body>hello</body>
</html>,
);

root.render(<App isClient={true} />);
await waitForAll([]);
expect(getMeaningfulChildren(document)).toEqual(
<html>
<head>
<link
rel="preload"
as="image"
imagesrcset="rpsrcset"
imagesizes="rpsizes"
imagesrcset="/server"
imagesizes="100vw"
referrerpolicy="no-referrer"
/>
<link rel="preload" as="image" href="client" />
<link rel="preload" as="image" imagesrcset="clientset" />
<link
rel="preload"
as="image"
imagesrcset="clientset"
imagesizes="clientsizes"
imagesrcset="/client"
imagesizes="100vw"
referrerpolicy="no-referrer"
/>
</head>
<body>hello</body>
Expand Down

0 comments on commit 24e2703

Please sign in to comment.