Fixes a race in the 404 hydration test #15

Merged
Sluijsens merged 1 commits from fix/404-hydration-h1 into master 2026-11-03 21:31:15 +01:00
+13 -1
View File
@@ -44,10 +44,18 @@ describe.each(widths)('hydratatie op %i px', (width) => {
expect(opened.violations).toEqual([]);
// Na de hydratatie nog steeds één titel en hoogstens één robots (V11)
// en één kop 1 voor wie de pagina ziet of hoort. Op een 404 staat
// er een tijdje (tot pendingMinMs, 0,5 s) naast de echte kop een
// kopie van de serverpagina in een display:none-sectie: die ziet
// en hoort niemand, maar querySelectorAll telt hem wel mee.
const counts = await page.evaluate(() => ({
titles: document.querySelectorAll('title').length,
robots: document.querySelectorAll('meta[name="robots"]').length,
h1: document.querySelectorAll('h1').length,
h1: [...document.querySelectorAll('h1')].filter(
(heading) =>
heading.checkVisibility() &&
!heading.closest('[aria-hidden="true"]'),
).length,
}));
const noindex =
notFoundPaths.includes(path) || path === '/privacyverklaring';
@@ -56,6 +64,10 @@ describe.each(widths)('hydratatie op %i px', (width) => {
robots: noindex ? 1 : 0,
h1: 1,
});
// Is de wissel klaar, dan is ook de verborgen kopie weg
await eventually(() =>
page.evaluate(() => document.querySelectorAll('h1').length),
).toBe(1);
},
);
});