-
-
Notifications
You must be signed in to change notification settings - Fork 5k
/
Copy pathroute-query.spec.ts
103 lines (91 loc) · 2.49 KB
/
route-query.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
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])
})
})