File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,36 @@ describe("LocationFull", () => {
6868 // Cleanup.
6969 unSub ( ) ;
7070 } ) ;
71+ test ( "Should unregister the provided callback when the returned function is called." , ( ) => {
72+ // Arrange.
73+ const callback = vi . fn ( ) ;
74+ const unSub = location . on ( 'beforeNavigate' , callback ) ;
75+
76+ // Act.
77+ unSub ( ) ;
78+
79+ // Assert.
80+ globalThis . window . history . pushState ( null , '' , 'http://example.com/other' ) ;
81+ expect ( callback ) . not . toHaveBeenCalled ( ) ;
82+ } ) ;
83+ test ( "Should not affect other handlers when unregistering one of the event handlers." , ( ) => {
84+ // Arrange.
85+ const callback1 = vi . fn ( ) ;
86+ const callback2 = vi . fn ( ) ;
87+ const unSub1 = location . on ( 'beforeNavigate' , callback1 ) ;
88+ const unSub2 = location . on ( 'beforeNavigate' , callback2 ) ;
89+
90+ // Act.
91+ unSub1 ( ) ;
92+
93+ // Assert.
94+ globalThis . window . history . pushState ( null , '' , 'http://example.com/other' ) ;
95+ expect ( callback1 ) . not . toHaveBeenCalled ( ) ;
96+ expect ( callback2 ) . toHaveBeenCalledOnce ( ) ;
97+
98+ // Cleanup.
99+ unSub2 ( ) ;
100+ } ) ;
71101 test . each ( [
72102 {
73103 method : 'push' ,
You can’t perform that action at this time.
0 commit comments