10000 correct typedef of Route by aryanbhosale · Pull Request #3901 · vuejs/vue-router · GitHub
[go: up one dir, main page]

Skip to content

correct typedef of Route #3901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
test for updated typedef for the query property
  • Loading branch information
aryanbhosale authored Aug 27, 2024
commit dee25cf83d47efc0e752cd24bfa06817bcb3470b
103 changes: 103 additions & 0 deletions types/test/route-query.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import VueRouter from '../index'
import { Route } from '../index'

const component = { template: '<div>test</div>' }

const router = new VueRouter({
routes: [
{ path: '/:id', component }
]
})

describe('Route query types', () => {
it('should handle string query parameter', () => {
const route: Route = {
path: '/test',
query: { foo: 'bar' },
params: {},
fullPath: '/test?foo=bar',
name: null,
hash: '',
matched: [],
redirectedFrom: undefined,
meta: {}
}

expect(typeof route.query.foo).toBe('string')
})

it('should handle null query parameter', () => {
const route: Route = {
path: '/test',
query: { foo: null },
params: {},
fullPath: '/test?foo',
name: null,
hash: '',
matched: [],
redirectedFrom: undefined,
meta: {}
}

expect(route.query.foo).toBeNull()
})

it('should handle array of strings query parameter', () => {
const route: Route = {
path: '/test',
query: { foo: ['bar', 'baz'] },
params: {},
fullPath: '/test?foo=bar&foo=baz',
name: null,
hash: '',
matched: [],
redirectedFrom: undefined,
meta: {}
}

expect(Array.isArray(route.query.foo)).toBe(true)
expect(route.query.foo).toEqual(['bar', 'baz'])
})

it('should handle array with null query parameter', () => {
const route: Route = {
path: '/test',
query: { foo: ['bar', null] },
params: {},
fullPath: '/test?foo=bar&foo',
name: null,
hash: '',
matched: [],
redirectedFrom: undefined,
meta: {}
}

expect(Array.isArray(route.query.foo)).toBe(true)
expect(route.query.foo).toEqual(['bar', null])
})

it('should handle mixed query parameters', () => {
const route: Route = {
path: '/test',
query: {
string: 'value',
nullValue: null,
stringArray: ['one', 'two'],
mixedArray: ['three', null]
},
params: {},
fullPath: '/test?string=value&nullValue&stringArray=one&stringArray=two&mixedArray=three&mixedArray',
name: null,
hash: '',
matched: [],
redirectedFrom: undefined,
meta: {}
}

expect(typeof route.query.string).toBe('string')
expect(route.query.nullValue).toBeNull()
expect(Array.isArray(route.query.stringArray)).toBe(true)
expect(Array.isArray(route.query.mixedArray)).toBe(true)
expect(route.query.mixedArray).toEqual(['three', null])
})
})
0