it('calls decode with a path', async () => {
const router = createRouter()
await router.push('/p/foo')
- expect(encoding.decode).toHaveBeenCalledTimes(1)
+ // one extra time for hash
+ expect(encoding.decode).toHaveBeenCalledTimes(2)
expect(encoding.decode).toHaveBeenNthCalledWith(1, 'foo')
})
it('calls decode with a path with repeatable params', async () => {
const router = createRouter()
await router.push('/p/foo/bar')
- expect(encoding.decode).toHaveBeenCalledTimes(2)
+ // one extra time for hash
+ expect(encoding.decode).toHaveBeenCalledTimes(3)
expect(encoding.decode).toHaveBeenNthCalledWith(1, 'foo', 0, ['foo', 'bar'])
expect(encoding.decode).toHaveBeenNthCalledWith(2, 'bar', 1, ['foo', 'bar'])
})
it('calls decode with query', async () => {
const router = createRouter()
await router.push('/?p=foo')
- expect(encoding.decode).toHaveBeenCalledTimes(2)
+ // one extra time for hash
+ expect(encoding.decode).toHaveBeenCalledTimes(3)
expect(encoding.decode).toHaveBeenNthCalledWith(1, 'p')
expect(encoding.decode).toHaveBeenNthCalledWith(2, 'foo')
})
hash: '#%',
})
})
+ it('decodes hash', async () => {
+ // @ts-ignore: override to make the difference
+ encoding.decode = () => '#d'
+ // @ts-ignore
+ encoding.encodeHash = () => '#e'
+ const router = createRouter()
+ await router.push('#%20')
+ expect(router.currentRoute.value).toMatchObject({
+ fullPath: '/#%20',
+ hash: '#d',
+ })
+ })
})
// locationNormalized is always a new object
return assign(locationNormalized, matchedRoute, {
params: decodeParams(matchedRoute.params),
+ hash: decode(locationNormalized.hash),
redirectedFrom: undefined,
href,
})