@@ -24,18 +24,15 @@ describe('Breadcrumbs (Astro)', () => {
2424 const renderedHtml = await response . text ( )
2525
2626 await withJsdomEnvironment ( async ( { window } ) => {
27- // Prefer document.write here so any hoisted tags (e.g., JSON-LD scripts) are also available.
28- window . document . open ( )
29- window . document . write ( renderedHtml )
30- window . document . close ( )
27+ const doc = new window . DOMParser ( ) . parseFromString ( renderedHtml , 'text/html' )
3128
32- const nav = window . document . querySelector ( 'nav[aria-label="Breadcrumbs"]' )
29+ const nav = doc . querySelector ( 'nav[aria-label="Breadcrumbs"]' )
3330 expect ( nav ) . toBeTruthy ( )
3431
35- const current = window . document . querySelector ( '[aria-current="page"]' )
32+ const current = doc . querySelector ( '[aria-current="page"]' )
3633 expect ( current ?. textContent ) . toContain ( 'My Post Title' )
3734
38- const links = window . document . querySelectorAll ( 'nav[aria-label="Breadcrumbs"] a[href]' )
35+ const links = doc . querySelectorAll < HTMLAnchorElement > ( 'nav[aria-label="Breadcrumbs"] a[href]' )
3936 expect ( links . length ) . toBeGreaterThan ( 0 )
4037 links . forEach ( link => {
4138 expect ( link . getAttribute ( 'href' ) ?. trim ( ) . length ) . toBeGreaterThan ( 0 )
@@ -46,7 +43,7 @@ describe('Breadcrumbs (Astro)', () => {
4643 expect ( link . tabIndex ) . toBeGreaterThanOrEqual ( 0 )
4744 } )
4845
49- const jsonLdScripts = window . document . querySelectorAll ( 'script[type="application/ld+json"]' )
46+ const jsonLdScripts = doc . querySelectorAll ( 'script[type="application/ld+json"]' )
5047 expect ( jsonLdScripts . length ) . toBe ( 1 )
5148
5249 const jsonLdScript = jsonLdScripts . item ( 0 )
0 commit comments