Skip to content

Commit 4c1fb66

Browse files
sbesh91claude
andcommitted
test: Fix _top/_parent navigation crashing WTR in CI
WTR runs tests inside an iframe. Clicking links with target="_top" or target="_parent" targets the WTR runner frame (canIntercept=false), so calling e.intercept() unconditionally throws and lets the navigation escape — crashing the entire test session. Fix by: - Checking canIntercept before calling e.intercept() in test handlers - Skipping _top/_parent tests (like _blank) since they can't be meaningfully tested in an iframe context Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent c77a900 commit 4c1fb66

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

test/router.test.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -575,10 +575,10 @@ describe('Router', () => {
575575

576576
let triedToNavigate = false;
577577
const handler = (e) => {
578-
e.intercept();
579578
if (e['preact-iso-ignored']) {
580579
triedToNavigate = true;
581580
}
581+
if (e.canIntercept) e.intercept();
582582
}
583583

584584
const App = () => {
@@ -615,15 +615,11 @@ describe('Router', () => {
615615
});
616616
}
617617

618-
// TODO: These tests are rather flakey, for some reason the additional handler
619-
// occasionally isn't running prior browser actually navigates away.
620618
for (const target of shouldNavigate) {
621619
it(`should allow default browser navigation for links with ${getName(target)}`, async () => {
622-
// Currently cross-window navigations, (e.g., `target="_blank"`), do not trigger a
623-
// `navigate` event, which makes this difficult to observe. Per the spec, however, this
624-
// might be a bug in Chrome's implementation:
625-
// https://github.com/WICG/navigation-api?tab=readme-ov-file#restrictions-on-firing-canceling-and-responding
626-
if (target === '_blank' || target === '_BLANK' || target === 'custom') return;
620+
// WTR runs tests in an iframe, so _top/_parent target the WTR runner frame
621+
// (canIntercept=false). _blank/custom don't fire navigate events at all.
622+
if (target === '_top' || target === '_parent' || target === '_blank' || target === '_BLANK' || target === 'custom') return;
627623

628624
scratch.querySelector(`#${createId(target)}`).click();
629625
await sleep(1);
@@ -649,10 +645,10 @@ describe('Router', () => {
649645

650646
let triedToNavigate = false;
651647
const handler = (e) => {
652-
e.intercept();
653648
if (e['preact-iso-ignored']) {
654649
triedToNavigate = true;
655650
}
651+
if (e.canIntercept) e.intercept();
656652
}
657653

658654
it('should support the `scope` prop (string)', async () => {

0 commit comments

Comments
 (0)