File tree Expand file tree Collapse file tree 1 file changed +15
-1
lines changed
packages/core/primitives/dom-navigation/testing Expand file tree Collapse file tree 1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -493,13 +493,17 @@ export class FakeNavigation implements Navigation {
493
493
* @internal
494
494
*/
495
495
userAgentTraverse ( navigateEvent : InternalFakeNavigateEvent ) {
496
+ const oldUrl = this . currentEntry . url ! ;
496
497
this . updateNavigationEntriesForSameDocumentNavigation ( navigateEvent ) ;
497
498
// Happens as part of "updating the document" steps https://whatpr.org/html/10919/browsing-the-web.html#updating-the-document
498
499
const popStateEvent = createPopStateEvent ( {
499
500
state : navigateEvent . destination . getHistoryState ( ) ,
500
501
} ) ;
501
502
this . window . dispatchEvent ( popStateEvent ) ;
502
- // TODO(atscott): If oldURL's fragment is not equal to entry's URL's fragment, then queue a global task to fire an event named hashchange
503
+ if ( navigateEvent . hashChange ) {
504
+ const hashchangeEvent = createHashChangeEvent ( oldUrl , this . currentEntry . url ! ) ;
505
+ this . window . dispatchEvent ( hashchangeEvent ) ;
506
+ }
503
507
}
504
508
505
509
/**
@@ -1061,6 +1065,16 @@ function createPopStateEvent({state}: {state: unknown}) {
1061
1065
return event as PopStateEvent ;
1062
1066
}
1063
1067
1068
+ function createHashChangeEvent ( newURL : string , oldURL : string ) {
1069
+ const event = new Event ( 'hashchange' , {
1070
+ bubbles : false ,
1071
+ cancelable : false ,
1072
+ } ) as { - readonly [ P in keyof HashChangeEvent ] : HashChangeEvent [ P ] } ;
1073
+ event . newURL = newURL ;
1074
+ event . oldURL = oldURL ;
1075
+ return event as HashChangeEvent ;
1076
+ }
1077
+
1064
1078
/**
1065
1079
* Fake equivalent of `NavigationDestination`.
1066
1080
*/
You can’t perform that action at this time.
0 commit comments