-
-
Notifications
You must be signed in to change notification settings - Fork 636
/
matchPath.spec.js
84 lines (76 loc) · 2.33 KB
/
matchPath.spec.js
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
import {matchPath} from 'inferno-router';
describe('matchPath', () => {
describe('with path="/"', () => {
it('returns correct url at "/"', () => {
const path = '/';
const pathname = '/';
const match = matchPath(pathname, path);
expect(match.url).toBe('/');
});
it('returns correct url at "/somewhere/else"', () => {
const path = '/';
const pathname = '/somewhere/else';
const match = matchPath(pathname, path);
expect(match.url).toBe('/');
});
});
describe('with path="/somewhere"', () => {
it('returns correct url at "/somewhere"', () => {
const path = '/somewhere';
const pathname = '/somewhere';
const match = matchPath(pathname, path);
expect(match.url).toBe('/somewhere');
});
it('returns correct url at "/somewhere/else"', () => {
const path = '/somewhere';
const pathname = '/somewhere/else';
const match = matchPath(pathname, path);
expect(match.url).toBe('/somewhere');
});
});
describe('with sensitive path', () => {
it('returns non-sensitive url', () => {
const options = {
path: '/SomeWhere'
};
const pathname = '/somewhere';
const match = matchPath(pathname, options);
expect(match.url).toBe('/somewhere');
});
it('returns sensitive url', () => {
const options = {
path: '/SomeWhere',
sensitive: true
};
const pathname = '/somewhere';
const match = matchPath(pathname, options);
expect(match).toBe(null);
});
});
describe('with no path', () => {
it('matches the root URL', () => {
const match = matchPath('/test-location/7', {});
expect(match.path).toBe('/');
expect(match.url).toBe('/');
expect(match.isExact).toBe(false);
expect(match.params).toEqual({});
});
});
describe('cache', () => {
it('creates a cache entry for each exact/strict pair', () => {
// true/false and false/true will collide when adding booleans
const trueFalse = matchPath('/one/two', {
path: '/one/two/',
exact: true,
strict: false
});
const falseTrue = matchPath('/one/two', {
path: '/one/two/',
exact: false,
strict: true
});
expect(!!trueFalse).toBe(true);
expect(!!falseTrue).toBe(false);
});
});
});