RouteLocation,
START_LOCATION_NORMALIZED,
} from '../src/types'
-import { RouterHistory } from '../src/history/common'
const routes: RouteRecord[] = [
{ path: '/', component: components.Home, name: 'home' },
},
]
-async function newRouter({ history }: { history?: RouterHistory } = {}) {
+async function newRouter({
+ history,
+ ...args
+}: Partial<Parameters<typeof createRouter>[0]> = {}) {
history = history || createMemoryHistory()
- const router = createRouter({ history, routes })
+ const router = createRouter({ history, routes, ...args })
await router.push('/')
return { history, router }
)
})
+ it('can allows the end user to override parseQuery', async () => {
+ const parseQuery = jest.fn()
+ const { router } = await newRouter({ parseQuery: parseQuery })
+ router.resolve('/foo?bar=baz')
+ expect(parseQuery).toHaveBeenCalled()
+ })
+
+ it('can allows the end user to stringify the query', async () => {
+ const stringifyQuery = jest.fn()
+ const { router } = await newRouter({ stringifyQuery: stringifyQuery })
+ router.resolve({ query: { foo: 'bar' } })
+ expect(stringifyQuery).toHaveBeenCalled()
+ })
+
it('can do initial navigation to /', async () => {
const router = createRouter({
history: createMemoryHistory(),
} from './utils'
import { useCallbacks } from './utils/callbacks'
import { encodeParam, decode } from './utils/encoding'
-import { normalizeQuery, parseQuery, stringifyQuery } from './utils/query'
+import {
+ normalizeQuery,
+ parseQuery as originalParseQuery,
+ stringifyQuery as originalStringifyQuery,
+} from './utils/query'
import { ref, Ref, markNonReactive, nextTick, App, warn } from 'vue'
import { RouteRecordNormalized } from './matcher/types'
import { Link } from './components/Link'
history: RouterHistory
routes: RouteRecord[]
scrollBehavior?: ScrollBehavior
+ parseQuery?: typeof originalParseQuery
+ stringifyQuery?: typeof originalStringifyQuery
// TODO: allow customizing encoding functions
}
history,
routes,
scrollBehavior,
+ parseQuery = originalParseQuery,
+ stringifyQuery = originalStringifyQuery,
}: RouterOptions): Router {
const matcher = createRouterMatcher(routes, {})