@@ -2,6 +2,7 @@ import fakePromise from 'faked-promise'
22import { createDom , tick , noGuard , newRouter as createRouter } from '../utils'
33import { RouteRecordRaw } from '../../src/types'
44import { RouteLocationRaw } from '../../src'
5+ import { vi , describe , expect , it , beforeAll } from 'vitest'
56
67const Home = { template : `<div>Home</div>` }
78const Foo = { template : `<div>Foo</div>` }
@@ -32,7 +33,7 @@ describe('router.beforeEach', () => {
3233 } )
3334
3435 it ( 'calls beforeEach guards on navigation' , async ( ) => {
35- const spy = jest . fn ( )
36+ const spy = vi . fn ( )
3637 const router = createRouter ( { routes } )
3738 router . beforeEach ( spy )
3839 spy . mockImplementationOnce ( noGuard )
@@ -41,7 +42,7 @@ describe('router.beforeEach', () => {
4142 } )
4243
4344 it ( 'can be removed' , async ( ) => {
44- const spy = jest . fn ( )
45+ const spy = vi . fn ( )
4546 const router = createRouter ( { routes } )
4647 const remove = router . beforeEach ( spy )
4748 remove ( )
@@ -51,7 +52,7 @@ describe('router.beforeEach', () => {
5152 } )
5253
5354 it ( 'does not call beforeEach guard if we were already on the page' , async ( ) => {
54- const spy = jest . fn ( )
55+ const spy = vi . fn ( )
5556 const router = createRouter ( { routes } )
5657 await router . push ( '/foo' )
5758 router . beforeEach ( spy )
@@ -61,7 +62,7 @@ describe('router.beforeEach', () => {
6162 } )
6263
6364 it ( 'calls beforeEach guards on navigation between children routes' , async ( ) => {
64- const spy = jest . fn ( )
65+ const spy = vi . fn ( )
6566 const router = createRouter ( { routes } )
6667 await router . push ( '/nested' )
6768 router . beforeEach ( spy )
@@ -83,7 +84,7 @@ describe('router.beforeEach', () => {
8384 } )
8485
8586 it ( 'can redirect to a different location' , async ( ) => {
86- const spy = jest . fn ( )
87+ const spy = vi . fn ( )
8788 const router = createRouter ( { routes } )
8889 await router . push ( '/foo' )
8990 spy . mockImplementation ( ( to , from , next ) => {
@@ -125,7 +126,7 @@ describe('router.beforeEach', () => {
125126 return
126127 } )
127128
128- const spy = jest . spyOn ( history , 'pushState' )
129+ const spy = vi . spyOn ( history , 'pushState' )
129130 await router . push ( { path : '/' , state : { a : 'a' } } )
130131 expect ( spy ) . toHaveBeenCalledTimes ( 1 )
131132 // called before redirect
@@ -142,7 +143,7 @@ describe('router.beforeEach', () => {
142143 const router = createRouter ( { routes } )
143144 await router . push ( '/foo' )
144145
145- const spy = jest . spyOn ( history , 'pushState' )
146+ const spy = vi . spyOn ( history , 'pushState' )
146147 await router . push ( { path : '/redirect' , state : { a : 'a' } } )
147148 expect ( spy ) . toHaveBeenCalledTimes ( 1 )
148149 // called before redirect
@@ -156,7 +157,7 @@ describe('router.beforeEach', () => {
156157 } )
157158
158159 async function assertRedirect ( redirectFn : ( i : string ) => RouteLocationRaw ) {
159- const spy = jest . fn ( )
160+ const spy = vi . fn ( )
160161 const router = createRouter ( { routes } )
161162 await router . push ( '/' )
162163 spy . mockImplementation ( ( to , from , next ) => {
@@ -185,7 +186,7 @@ describe('router.beforeEach', () => {
185186 } )
186187
187188 it ( 'is called when changing params' , async ( ) => {
188- const spy = jest . fn ( )
189+ const spy = vi . fn ( )
189190 const router = createRouter ( { routes : [ ...routes ] } )
190191 await router . push ( '/n/2' )
191192 spy . mockImplementation ( noGuard )
@@ -196,7 +197,7 @@ describe('router.beforeEach', () => {
196197 } )
197198
198199 it ( 'is not called with same params' , async ( ) => {
199- const spy = jest . fn ( )
200+ const spy = vi . fn ( )
200201 const router = createRouter ( { routes : [ ...routes ] } )
201202 await router . push ( '/n/2' )
202203 spy . mockImplementation ( noGuard )
@@ -224,15 +225,15 @@ describe('router.beforeEach', () => {
224225 const [ p1 , r1 ] = fakePromise ( )
225226 const [ p2 , r2 ] = fakePromise ( )
226227 const router = createRouter ( { routes } )
227- const guard1 = jest . fn ( )
228+ const guard1 = vi . fn ( )
228229 let order = 0
229230 guard1 . mockImplementationOnce ( async ( to , from , next ) => {
230231 expect ( order ++ ) . toBe ( 0 )
231232 await p1
232233 next ( )
233234 } )
234235 router . beforeEach ( guard1 )
235- const guard2 = jest . fn ( )
236+ const guard2 = vi . fn ( )
236237 guard2 . mockImplementationOnce ( async ( to , from , next ) => {
237238 expect ( order ++ ) . toBe ( 1 )
238239 await p2
@@ -256,7 +257,7 @@ describe('router.beforeEach', () => {
256257 } )
257258
258259 it ( 'adds meta information' , async ( ) => {
259- const spy = jest . fn ( )
260+ const spy = vi . fn ( )
260261 const router = createRouter ( { routes } )
261262 router . beforeEach ( spy )
262263 spy . mockImplementationOnce ( noGuard )
0 commit comments