-
Notifications
You must be signed in to change notification settings - Fork 960
/
memory-test.js
186 lines (157 loc) · 5.29 KB
/
memory-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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import expect from "expect";
import { createMemoryHistory } from "history";
import Listen from "./TestSequences/Listen.js";
import InitialLocationHasKey from "./TestSequences/InitialLocationHasKey.js";
import PushNewLocation from "./TestSequences/PushNewLocation.js";
import PushSamePath from "./TestSequences/PushSamePath.js";
import PushState from "./TestSequences/PushState.js";
import PushURL from "./TestSequences/PushURL.js";
import PushMissingPathname from "./TestSequences/PushMissingPathname.js";
import PushRelativePathnameWarning from "./TestSequences/PushRelativePathnameWarning.js";
import ReplaceNewLocation from "./TestSequences/ReplaceNewLocation.js";
import ReplaceSamePath from "./TestSequences/ReplaceSamePath.js";
import ReplaceState from "./TestSequences/ReplaceState.js";
import ReplaceURL from "./TestSequences/ReplaceURL.js";
import EncodedReservedCharacters from "./TestSequences/EncodedReservedCharacters.js";
import GoBack from "./TestSequences/GoBack.js";
import GoForward from "./TestSequences/GoForward.js";
import BlockEverything from "./TestSequences/BlockEverything.js";
import BlockPopWithoutListening from "./TestSequences/BlockPopWithoutListening.js";
describe("a memory history", () => {
let history;
beforeEach(() => {
history = createMemoryHistory();
});
it("has an index property", () => {
expect(typeof history.index).toBe("number");
});
it("knows how to create hrefs", () => {
const href = history.createHref({
pathname: "/the/path",
search: "?the=query",
hash: "#the-hash",
});
expect(href).toEqual("/the/path?the=query#the-hash");
});
it("knows how to create hrefs from strings", () => {
const href = history.createHref("/the/path?the=query#the-hash");
expect(href).toEqual("/the/path?the=query#the-hash");
});
it("does not encode the generated path", () => {
const encodedHref = history.createHref({
pathname: "/%23abc",
});
expect(encodedHref).toEqual("/%23abc");
const unencodedHref = history.createHref({
pathname: "/#abc",
});
expect(unencodedHref).toEqual("/#abc");
});
describe("listen", () => {
it("does not immediately call listeners", (done) => {
Listen(history, done);
});
});
describe("the initial location", () => {
it("has a key", (done) => {
InitialLocationHasKey(history, done);
});
});
describe("push a new path", () => {
it("calls change listeners with the new location", (done) => {
PushNewLocation(history, done);
});
});
describe("push the same path", () => {
it("calls change listeners with the new location", (done) => {
PushSamePath(history, done);
});
});
describe("push state", () => {
it("calls change listeners with the new location", (done) => {
PushState(history, done);
});
});
describe("push URL", () => {
it("calls change listeners with the new location", (done) => {
PushURL(history, done);
});
});
describe("push with no pathname", () => {
it("reuses the current location pathname", (done) => {
PushMissingPathname(history, done);
});
});
describe("push with a relative pathname", () => {
it("issues a warning", (done) => {
PushRelativePathnameWarning(history, done);
});
});
describe("replace a new path", () => {
it("calls change listeners with the new location", (done) => {
ReplaceNewLocation(history, done);
});
});
describe("replace the same path", () => {
it("calls change listeners with the new location", (done) => {
ReplaceSamePath(history, done);
});
});
describe("replace state", () => {
it("calls change listeners with the new location", (done) => {
ReplaceState(history, done);
});
});
describe("replace URL", () => {
it("calls change listeners with the new location", (done) => {
ReplaceURL(history, done);
});
});
describe("location created with encoded/unencoded reserved characters", () => {
it("produces different location objects", (done) => {
EncodedReservedCharacters(history, done);
});
});
describe("back", () => {
it("calls change listeners with the previous location", (done) => {
GoBack(history, done);
});
});
describe("forward", () => {
it("calls change listeners with the next location", (done) => {
GoForward(history, done);
});
});
describe("block", () => {
it("blocks all transitions", (done) => {
BlockEverything(history, done);
});
});
describe("block a POP without listening", () => {
it("receives the next location and action as arguments", (done) => {
BlockPopWithoutListening(history, done);
});
});
});
describe("a memory history with some initial entries", () => {
it("clamps the initial index to a valid value", () => {
let history = createMemoryHistory({
initialEntries: ["/one", "/two", "/three"],
initialIndex: 3, // invalid
});
expect(history.index).toBe(2);
});
it("starts at the last entry by default", () => {
let history = createMemoryHistory({
initialEntries: ["/one", "/two", "/three"],
});
expect(history.index).toBe(2);
expect(history.location).toMatchObject({
pathname: "/three",
search: "",
hash: "",
state: null,
key: expect.any(String),
});
});
});