Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(query): empty object with custom stringify
  • Loading branch information
posva committed Aug 9, 2021
1 parent b0b02ae commit 4dd2fbf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 15 additions & 4 deletions __tests__/router.spec.ts
Expand Up @@ -149,17 +149,28 @@ describe('Router', () => {
})

it('allows to customize parseQuery', async () => {
const parseQuery = jest.fn()
const parseQuery = jest.fn(_ => ({}))
const { router } = await newRouter({ parseQuery })
router.resolve('/foo?bar=baz')
const to = router.resolve('/foo?bar=baz')
expect(parseQuery).toHaveBeenCalledWith('bar=baz')
expect(to.query).toEqual({})
})

it('allows to customize stringifyQuery', async () => {
const stringifyQuery = jest.fn()
const stringifyQuery = jest.fn(_ => '')
const { router } = await newRouter({ stringifyQuery })
router.resolve({ query: { foo: 'bar' } })
const to = router.resolve({ query: { foo: 'bar' } })
expect(stringifyQuery).toHaveBeenCalledWith({ foo: 'bar' })
expect(to.query).toEqual({ foo: 'bar' })
expect(to.fullPath).toBe('/')
})

it('creates an empty query with no query', async () => {
const stringifyQuery = jest.fn(_ => '')
const { router } = await newRouter({ stringifyQuery })
const to = router.resolve({ hash: '#a' })
expect(stringifyQuery).not.toHaveBeenCalled()
expect(to.query).toEqual({})
})

it('merges meta properties from parent to child', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/router.ts
Expand Up @@ -542,7 +542,7 @@ export function createRouter(options: RouterOptions): Router {
// https://github.com/vuejs/vue-router-next/issues/328#issuecomment-649481567
stringifyQuery === originalStringifyQuery
? normalizeQuery(rawLocation.query)
: (rawLocation.query as LocationQuery),
: ((rawLocation.query || {}) as LocationQuery),
},
matchedRoute,
{
Expand Down

0 comments on commit 4dd2fbf

Please sign in to comment.