@@ -64,4 +64,35 @@ describe('history API', () => {
6464 history . go ( - 1 ) ;
6565 } ) ;
6666 } ) ;
67+
68+ it ( 'hashchange should fire when history back' , ( done ) => {
69+ expect ( location . pathname ) . toBe ( '/public/core.build.js' ) ;
70+ history . pushState ( { name : 2 } , '' , '#/page_1' ) ;
71+ function onHashChange ( e : HashChangeEvent ) {
72+ expect ( new URL ( e . oldURL ) . hash ) . toBe ( '#/page_1' ) ;
73+ expect ( new URL ( e . newURL ) . hash ) . toBe ( '#hash=hashValue' ) ;
74+ window . removeEventListener ( 'hashchange' , onHashChange ) ;
75+ done ( ) ;
76+ }
77+ window . addEventListener ( 'hashchange' , onHashChange ) ;
78+ requestAnimationFrame ( ( ) => {
79+ history . back ( ) ;
80+ } ) ;
81+ } ) ;
82+
83+ it ( 'hashchange when go back should work' , ( done ) => {
84+ expect ( location . pathname ) . toBe ( '/public/core.build.js' ) ;
85+ history . replaceState ( { name : 0 } , '' ) ;
86+ history . pushState ( { name : 2 } , '' , '#/page_1' ) ;
87+ function onHashChange ( e : HashChangeEvent ) {
88+ expect ( new URL ( e . oldURL ) . hash ) . toBe ( '#/page_1' ) ;
89+ expect ( new URL ( e . newURL ) . hash ) . toBe ( '#hash=hashValue' ) ;
90+ window . removeEventListener ( 'popstate' , onHashChange ) ;
91+ done ( ) ;
92+ }
93+ window . addEventListener ( 'hashchange' , onHashChange ) ;
94+ requestAnimationFrame ( ( ) => {
95+ history . go ( - 1 ) ;
96+ } ) ;
97+ } ) ;
6798} ) ;
0 commit comments