forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver-utils.test.ts
More file actions
73 lines (63 loc) · 2.02 KB
/
server-utils.test.ts
File metadata and controls
73 lines (63 loc) · 2.02 KB
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
import { getUtils } from './server-utils'
describe('getParamsFromRouteMatches', () => {
it('should return nothing for a non-dynamic route', () => {
const { getParamsFromRouteMatches } = getUtils({
page: '/',
basePath: '',
rewrites: {},
i18n: undefined,
pageIsDynamic: false,
caseSensitive: false,
})
const params = getParamsFromRouteMatches('nxtPslug=hello-world')
expect(params).toEqual(null)
})
it('should return the params from the route matches', () => {
const { getParamsFromRouteMatches } = getUtils({
page: '/[slug]',
basePath: '',
rewrites: {},
i18n: undefined,
pageIsDynamic: true,
caseSensitive: false,
})
const params = getParamsFromRouteMatches('nxtPslug=hello-world')
expect(params).toEqual({ slug: 'hello-world' })
})
it('should handle optional params', () => {
const { getParamsFromRouteMatches } = getUtils({
page: '/[slug]/[[...optional]]',
basePath: '',
rewrites: {},
i18n: undefined,
pageIsDynamic: true,
caseSensitive: false,
})
// Missing optional param
let params = getParamsFromRouteMatches('nxtPslug=hello-world')
expect(params).toEqual({ slug: 'hello-world' })
// Providing optional param
params = getParamsFromRouteMatches(
'nxtPslug=hello-world&nxtPoptional=im-optional'
)
expect(params).toEqual({ slug: 'hello-world', optional: ['im-optional'] })
})
it('should handle rest params', () => {
const { getParamsFromRouteMatches } = getUtils({
page: '/[slug]/[...rest]',
basePath: '',
rewrites: {},
i18n: undefined,
pageIsDynamic: true,
caseSensitive: false,
})
// Missing rest param
let params = getParamsFromRouteMatches('nxtPslug=hello-world')
expect(params).toEqual(null)
// Providing rest param
params = getParamsFromRouteMatches(
'nxtPslug=hello-world&nxtPrest=im-the/rest'
)
expect(params).toEqual({ slug: 'hello-world', rest: ['im-the', 'rest'] })
})
})