forked from remix-run/react-router
/
matchPath-test.js
104 lines (93 loc) · 3.08 KB
/
matchPath-test.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import matchPath from "../matchPath";
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 an array of paths", () => {
it('return the correct url at "/elsewhere"', () => {
const path = ["/somewhere", "/elsewhere"];
const pathname = "/elsewhere";
const match = matchPath(pathname, { path });
expect(match.url).toBe("/elsewhere");
});
it('returns correct url at "/elsewhere/else"', () => {
const path = ["/somewhere", "/elsewhere"];
const pathname = "/elsewhere/else";
const match = matchPath(pathname, { path });
expect(match.url).toBe("/elsewhere");
});
it('returns correct url at "/elsewhere/else" with path "/" in array', () => {
const path = ["/somewhere", "/"];
const pathname = "/elsewhere/else";
const match = matchPath(pathname, { path });
expect(match.url).toBe("/");
});
it('returns correct url at "/somewhere" with path "/" in array', () => {
const path = ["/somewhere", "/"];
const pathname = "/somewhere";
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("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);
});
});
});