Skip to content

Commit dee25cf

Browse files
authored
test for updated typedef for the query property
1 parent 1ee9a1b commit dee25cf

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed

Diff for: types/test/route-query.spec.ts

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import VueRouter from '../index'
2+
import { Route } from '../index'
3+
4+
const component = { template: '<div>test</div>' }
5+
6+
const router = new VueRouter({
7+
routes: [
8+
{ path: '/:id', component }
9+
]
10+
})
11+
12+
describe('Route query types', () => {
13+
it('should handle string query parameter', () => {
14+
const route: Route = {
15+
path: '/test',
16+
query: { foo: 'bar' },
17+
params: {},
18+
fullPath: '/test?foo=bar',
19+
name: null,
20+
hash: '',
21+
matched: [],
22+
redirectedFrom: undefined,
23+
meta: {}
24+
}
25+
26+
expect(typeof route.query.foo).toBe('string')
27+
})
28+
29+
it('should handle null query parameter', () => {
30+
const route: Route = {
31+
path: '/test',
32+
query: { foo: null },
33+
params: {},
34+
fullPath: '/test?foo',
35+
name: null,
36+
hash: '',
37+
matched: [],
38+
redirectedFrom: undefined,
39+
meta: {}
40+
}
41+
42+
expect(route.query.foo).toBeNull()
43+
})
44+
45+
it('should handle array of strings query parameter', () => {
46+
const route: Route = {
47+
path: '/test',
48+
query: { foo: ['bar', 'baz'] },
49+
params: {},
50+
fullPath: '/test?foo=bar&foo=baz',
51+
name: null,
52+
hash: '',
53+
matched: [],
54+
redirectedFrom: undefined,
55+
meta: {}
56+
}
57+
58+
expect(Array.isArray(route.query.foo)).toBe(true)
59+
expect(route.query.foo).toEqual(['bar', 'baz'])
60+
})
61+
62+
it('should handle array with null query parameter', () => {
63+
const route: Route = {
64+
path: '/test',
65+
query: { foo: ['bar', null] },
66+
params: {},
67+
fullPath: '/test?foo=bar&foo',
68+
name: null,
69+
hash: '',
70+
matched: [],
71+
redirectedFrom: undefined,
72+
meta: {}
73+
}
74+
75+
expect(Array.isArray(route.query.foo)).toBe(true)
76+
expect(route.query.foo).toEqual(['bar', null])
77+
})
78+
79+
it('should handle mixed query parameters', () => {
80+
const route: Route = {
81+
path: '/test',
82+
query: {
83+
string: 'value',
84+
nullValue: null,
85+
stringArray: ['one', 'two'],
86+
mixedArray: ['three', null]
87+
},
88+
params: {},
89+
fullPath: '/test?string=value&nullValue&stringArray=one&stringArray=two&mixedArray=three&mixedArray',
90+
name: null,
91+
hash: '',
92+
matched: [],
93+
redirectedFrom: undefined,
94+
meta: {}
95+
}
96+
97+
expect(typeof route.query.string).toBe('string')
98+
expect(route.query.nullValue).toBeNull()
99+
expect(Array.isArray(route.query.stringArray)).toBe(true)
100+
expect(Array.isArray(route.query.mixedArray)).toBe(true)
101+
expect(route.query.mixedArray).toEqual(['three', null])
102+
})
103+
})

0 commit comments

Comments
 (0)