-
Notifications
You must be signed in to change notification settings - Fork 214
Expand file tree
/
Copy pathroute-match-utils.test.js
More file actions
55 lines (47 loc) · 2.18 KB
/
route-match-utils.test.js
File metadata and controls
55 lines (47 loc) · 2.18 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
/*
* Copyright (c) 2025, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import {matchPath} from './route-match-utils'
describe('matchPath', () => {
const NullComponent = () => null
const routes = [
{path: '/', component: NullComponent},
{path: '/about', component: NullComponent},
{path: '/contact', component: NullComponent},
{path: '/products/*', component: NullComponent},
{path: '/products/:id', component: NullComponent},
{path: '*', component: NullComponent}
]
it('should return the matching route', () => {
const result = matchPath('/about', routes)
expect(result).toEqual({path: '/about', component: NullComponent})
})
it('should return the matching route with wildcard if filterWildcardRoutes is false', () => {
const result = matchPath('/products/123', routes)
expect(result).toEqual({path: '/products/*', component: NullComponent})
})
it('should return the matching route without wildcard if filterWildcardRoutes is true', () => {
const result = matchPath('/products/123', routes, {filterWildcardRoutes: true})
expect(result).toEqual({path: '/products/:id', component: NullComponent})
})
it('should return undefined if no match is found and filterWildcardRoutes is true', () => {
const result = matchPath('/none', routes, {filterWildcardRoutes: true})
expect(result).toBeUndefined()
})
it('should return undefined for an undefined path', () => {
const result = matchPath(undefined, routes)
expect(result).toBeUndefined()
})
it('should ignore undefined paths in the routes array', () => {
const routesWithUndefined = [
{path: '/', component: NullComponent},
{path: undefined, component: NullComponent},
{path: '/about', component: NullComponent}
]
const result = matchPath('/about', routesWithUndefined, {filterWildcardRoutes: true})
expect(result).toEqual({path: '/about', component: NullComponent})
})
})