@@ -43,9 +43,25 @@ describe('beforeLoad skip or exec', () => {
4343 } )
4444
4545 test ( 'exec on regular nav' , async ( ) => {
46- const beforeLoad = vi . fn ( )
46+ const beforeLoad = vi . fn ( ( ) => Promise . resolve ( { hello : 'world' } ) )
4747 const router = setup ( { beforeLoad } )
48- await router . navigate ( { to : '/foo' } )
48+ const navigation = router . navigate ( { to : '/foo' } )
49+ expect ( beforeLoad ) . toHaveBeenCalledTimes ( 1 )
50+ expect ( router . state . pendingMatches ) . toEqual (
51+ expect . arrayContaining ( [ expect . objectContaining ( { id : '/foo' } ) ] ) ,
52+ )
53+ await navigation
54+ expect ( router . state . location . pathname ) . toBe ( '/foo' )
55+ expect ( router . state . matches ) . toEqual (
56+ expect . arrayContaining ( [
57+ expect . objectContaining ( {
58+ id : '/foo' ,
59+ context : {
60+ hello : 'world' ,
61+ } ,
62+ } ) ,
63+ ] ) ,
64+ )
4965 expect ( beforeLoad ) . toHaveBeenCalledTimes ( 1 )
5066 } )
5167
@@ -56,15 +72,21 @@ describe('beforeLoad skip or exec', () => {
5672 const router = setup ( { beforeLoad } )
5773 router . preloadRoute ( { to : '/foo' } )
5874 await Promise . resolve ( )
75+ expect ( router . state . cachedMatches ) . toEqual (
76+ expect . arrayContaining ( [ expect . objectContaining ( { id : '/foo' } ) ] ) ,
77+ )
5978 await router . navigate ( { to : '/foo' } )
6079
6180 expect ( beforeLoad ) . toHaveBeenCalledTimes ( 1 )
6281 } )
6382
6483 test ( 'skip if preload resolved successfully' , async ( ) => {
65- const beforeLoad = vi . fn ( ( ) => Promise . resolve ( ) )
84+ const beforeLoad = vi . fn ( )
6685 const router = setup ( { beforeLoad } )
6786 await router . preloadRoute ( { to : '/foo' } )
87+ expect ( router . state . cachedMatches ) . toEqual (
88+ expect . arrayContaining ( [ expect . objectContaining ( { id : '/foo' } ) ] ) ,
89+ )
6890 await router . navigate ( { to : '/foo' } )
6991
7092 expect ( beforeLoad ) . toHaveBeenCalledTimes ( 1 )
0 commit comments