Prerenders every page as HTML #14
@@ -76,16 +76,30 @@ describe('homepage ?pakket= on a direct load', () => {
|
|||||||
// Start does not recognise the catch-all match of another path (its id holds
|
// Start does not recognise the catch-all match of another path (its id holds
|
||||||
// the path), so the browser renders that match itself. Its first render must
|
// the path), so the browser renders that match itself. Its first render must
|
||||||
// be the page the HTML shows, or React reports a mismatch (BR-404-05, V12).
|
// be the page the HTML shows, or React reports a mismatch (BR-404-05, V12).
|
||||||
|
//
|
||||||
|
// Router keeps the pending copy of a route on screen for at least
|
||||||
|
// pendingMinMs (500 ms by default) and then replaces it with the real page:
|
||||||
|
// the heading found first is detached a moment later (measured: found after
|
||||||
|
// 6 to 40 ms, replaced after about 480 ms). On a slow machine that happens
|
||||||
|
// between finding and asserting. So look the element up again at every
|
||||||
|
// check, and let the swap happen before the hydration errors are read.
|
||||||
|
const PENDING_MIN_MS = 500;
|
||||||
|
|
||||||
|
async function settled(find: () => HTMLElement) {
|
||||||
|
await waitFor(() => expect(find()).toBeInTheDocument());
|
||||||
|
// This timer is started after the router's own, so it fires after the swap
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, PENDING_MIN_MS + 100));
|
||||||
|
await waitFor(() => expect(find()).toBeInTheDocument());
|
||||||
|
}
|
||||||
|
|
||||||
describe('404 page served for another URL', () => {
|
describe('404 page served for another URL', () => {
|
||||||
it.each(['/onbekend', '/404.html', '/over-mij/x'])(
|
it.each(['/onbekend', '/404.html', '/over-mij/x'])(
|
||||||
'hydrates %s without a mismatch',
|
'hydrates %s without a mismatch',
|
||||||
async (url) => {
|
async (url) => {
|
||||||
const { errors } = await hydrateAppAsStart('/404', url);
|
const { errors } = await hydrateAppAsStart('/404', url);
|
||||||
expect(
|
await settled(() =>
|
||||||
await screen.findByRole('heading', {
|
screen.getByRole('heading', { name: 'Pagina niet gevonden' }),
|
||||||
name: 'Pagina niet gevonden',
|
);
|
||||||
}),
|
|
||||||
).toBeInTheDocument();
|
|
||||||
expect(errors).toEqual([]);
|
expect(errors).toEqual([]);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -95,9 +109,7 @@ describe('404 page served for another URL', () => {
|
|||||||
'/404',
|
'/404',
|
||||||
'/soorten-fotoshoots/onbekend',
|
'/soorten-fotoshoots/onbekend',
|
||||||
);
|
);
|
||||||
expect(
|
await settled(() => screen.getByTestId('status-page-section-link'));
|
||||||
await screen.findByTestId('status-page-section-link'),
|
|
||||||
).toBeInTheDocument();
|
|
||||||
expect(errors).toEqual([]);
|
expect(errors).toEqual([]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user