@esmx/router 3.0.0-rc.29 → 3.0.0-rc.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.zh-CN.md +82 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.mjs +0 -1
- package/dist/navigation.mjs +4 -4
- package/package.json +3 -3
- package/src/index.ts +0 -3
- package/src/navigation.ts +4 -4
- package/dist/index.test.d.ts +0 -1
- package/dist/index.test.mjs +0 -8
- package/dist/location.test.d.ts +0 -8
- package/dist/location.test.mjs +0 -370
- package/dist/matcher.test.d.ts +0 -1
- package/dist/matcher.test.mjs +0 -1492
- package/dist/micro-app.dom.test.d.ts +0 -1
- package/dist/micro-app.dom.test.mjs +0 -532
- package/dist/navigation.test.d.ts +0 -1
- package/dist/navigation.test.mjs +0 -681
- package/dist/route-task.test.d.ts +0 -1
- package/dist/route-task.test.mjs +0 -673
- package/dist/route-transition.test.d.ts +0 -1
- package/dist/route-transition.test.mjs +0 -146
- package/dist/route.test.d.ts +0 -1
- package/dist/route.test.mjs +0 -1664
- package/dist/router-back.test.d.ts +0 -1
- package/dist/router-back.test.mjs +0 -361
- package/dist/router-forward.test.d.ts +0 -1
- package/dist/router-forward.test.mjs +0 -376
- package/dist/router-go.test.d.ts +0 -1
- package/dist/router-go.test.mjs +0 -73
- package/dist/router-guards-cleanup.test.d.ts +0 -1
- package/dist/router-guards-cleanup.test.mjs +0 -437
- package/dist/router-push.test.d.ts +0 -1
- package/dist/router-push.test.mjs +0 -115
- package/dist/router-replace.test.d.ts +0 -1
- package/dist/router-replace.test.mjs +0 -114
- package/dist/router-resolve.test.d.ts +0 -1
- package/dist/router-resolve.test.mjs +0 -393
- package/dist/router-restart-app.dom.test.d.ts +0 -1
- package/dist/router-restart-app.dom.test.mjs +0 -616
- package/dist/router-window-navigation.test.d.ts +0 -1
- package/dist/router-window-navigation.test.mjs +0 -359
- package/dist/util.test.d.ts +0 -1
- package/dist/util.test.mjs +0 -1020
- package/src/index.test.ts +0 -9
- package/src/location.test.ts +0 -406
- package/src/matcher.test.ts +0 -1685
- package/src/micro-app.dom.test.ts +0 -708
- package/src/navigation.test.ts +0 -858
- package/src/route-task.test.ts +0 -901
- package/src/route-transition.test.ts +0 -178
- package/src/route.test.ts +0 -2014
- package/src/router-back.test.ts +0 -487
- package/src/router-forward.test.ts +0 -506
- package/src/router-go.test.ts +0 -91
- package/src/router-guards-cleanup.test.ts +0 -595
- package/src/router-push.test.ts +0 -140
- package/src/router-replace.test.ts +0 -139
- package/src/router-resolve.test.ts +0 -475
- package/src/router-restart-app.dom.test.ts +0 -783
- package/src/router-window-navigation.test.ts +0 -457
- package/src/util.test.ts +0 -1262
|
@@ -1,376 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
|
|
2
|
-
import { Router } from "./router.mjs";
|
|
3
|
-
import { RouteType, RouterMode } from "./types.mjs";
|
|
4
|
-
describe("Router.forward Tests", () => {
|
|
5
|
-
let router;
|
|
6
|
-
let executionLog;
|
|
7
|
-
beforeEach(async () => {
|
|
8
|
-
executionLog = [];
|
|
9
|
-
router = new Router({
|
|
10
|
-
mode: RouterMode.memory,
|
|
11
|
-
base: new URL("http://localhost:3000/"),
|
|
12
|
-
fallback: (to, from) => {
|
|
13
|
-
executionLog.push("location-handler-".concat(to.path));
|
|
14
|
-
},
|
|
15
|
-
routes: [
|
|
16
|
-
{
|
|
17
|
-
path: "/",
|
|
18
|
-
component: () => "Home"
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
path: "/about",
|
|
22
|
-
component: () => "About"
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
path: "/user/:id",
|
|
26
|
-
component: () => "User",
|
|
27
|
-
beforeEnter: (to) => {
|
|
28
|
-
if (to.params.id === "blocked") {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
if (to.params.id === "redirect") {
|
|
32
|
-
return "/about";
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
path: "/async",
|
|
38
|
-
asyncComponent: () => new Promise((resolve) => {
|
|
39
|
-
setTimeout(() => resolve("AsyncComponent"), 10);
|
|
40
|
-
})
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
path: "/async-error",
|
|
44
|
-
asyncComponent: () => new Promise((_, reject) => {
|
|
45
|
-
setTimeout(
|
|
46
|
-
() => reject(new Error("Load failed")),
|
|
47
|
-
10
|
|
48
|
-
);
|
|
49
|
-
})
|
|
50
|
-
}
|
|
51
|
-
]
|
|
52
|
-
});
|
|
53
|
-
await router.push("/");
|
|
54
|
-
});
|
|
55
|
-
afterEach(() => {
|
|
56
|
-
router.destroy();
|
|
57
|
-
});
|
|
58
|
-
describe("\u{1F3AF} Core Behavior", () => {
|
|
59
|
-
test("forward should return Promise<Route | null>", async () => {
|
|
60
|
-
await router.push("/about");
|
|
61
|
-
await router.back();
|
|
62
|
-
const route = await router.forward();
|
|
63
|
-
expect(route).toBeInstanceOf(Object);
|
|
64
|
-
expect(route == null ? void 0 : route.path).toBe("/about");
|
|
65
|
-
expect(route == null ? void 0 : route.handle).not.toBeNull();
|
|
66
|
-
});
|
|
67
|
-
test("forward should navigate to next route", async () => {
|
|
68
|
-
await router.push("/about");
|
|
69
|
-
await router.push("/user/123");
|
|
70
|
-
await router.back();
|
|
71
|
-
const forwardRoute = await router.forward();
|
|
72
|
-
expect(forwardRoute == null ? void 0 : forwardRoute.path).toBe("/user/123");
|
|
73
|
-
expect(router.route.path).toBe("/user/123");
|
|
74
|
-
});
|
|
75
|
-
test("forward should update router state", async () => {
|
|
76
|
-
await router.push("/about");
|
|
77
|
-
await router.back();
|
|
78
|
-
await router.forward();
|
|
79
|
-
expect(router.route.path).toBe("/about");
|
|
80
|
-
expect(router.route.handle).not.toBeNull();
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
describe("\u{1F504} History Navigation Logic", () => {
|
|
84
|
-
test("forward should navigate based on history stack", async () => {
|
|
85
|
-
await router.push("/about");
|
|
86
|
-
await router.push("/user/123");
|
|
87
|
-
await router.back();
|
|
88
|
-
await router.back();
|
|
89
|
-
const route1 = await router.forward();
|
|
90
|
-
expect(route1 == null ? void 0 : route1.path).toBe("/about");
|
|
91
|
-
expect(router.route.path).toBe("/about");
|
|
92
|
-
const route2 = await router.forward();
|
|
93
|
-
expect(route2 == null ? void 0 : route2.path).toBe("/user/123");
|
|
94
|
-
expect(router.route.path).toBe("/user/123");
|
|
95
|
-
});
|
|
96
|
-
test("forward beyond history boundaries should return null", async () => {
|
|
97
|
-
await router.push("/about");
|
|
98
|
-
await router.push("/user/123");
|
|
99
|
-
const route = await router.forward();
|
|
100
|
-
expect(route).toBe(null);
|
|
101
|
-
expect(router.route.path).toBe("/user/123");
|
|
102
|
-
});
|
|
103
|
-
test("forward should return correct RouteType", async () => {
|
|
104
|
-
await router.push("/about");
|
|
105
|
-
await router.back();
|
|
106
|
-
const route = await router.forward();
|
|
107
|
-
expect(route == null ? void 0 : route.type).toBe(RouteType.forward);
|
|
108
|
-
});
|
|
109
|
-
test("forward should keep isPush as false", async () => {
|
|
110
|
-
await router.push("/about");
|
|
111
|
-
await router.back();
|
|
112
|
-
const route = await router.forward();
|
|
113
|
-
expect(route == null ? void 0 : route.isPush).toBe(false);
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
describe("\u{1F3C3} Concurrency Control", () => {
|
|
117
|
-
test("later initiated forward should cancel earlier forward", async () => {
|
|
118
|
-
await router.push("/about");
|
|
119
|
-
await router.push("/user/123");
|
|
120
|
-
await router.back();
|
|
121
|
-
await router.back();
|
|
122
|
-
const [firstResult, secondResult] = await Promise.all([
|
|
123
|
-
router.forward(),
|
|
124
|
-
// First operation, should succeed
|
|
125
|
-
router.forward()
|
|
126
|
-
// Second operation, returns null due to first one in progress
|
|
127
|
-
]);
|
|
128
|
-
expect(firstResult == null ? void 0 : firstResult.handle).not.toBeNull();
|
|
129
|
-
expect(secondResult).toBe(null);
|
|
130
|
-
expect(router.route.path).toBe("/about");
|
|
131
|
-
});
|
|
132
|
-
test("cancelled tasks should not affect micro-app state", async () => {
|
|
133
|
-
const updateSpy = vi.spyOn(router.microApp, "_update");
|
|
134
|
-
await router.push("/about");
|
|
135
|
-
await router.push("/user/123");
|
|
136
|
-
await router.back();
|
|
137
|
-
await router.back();
|
|
138
|
-
updateSpy.mockClear();
|
|
139
|
-
const [firstResult, secondResult] = await Promise.all([
|
|
140
|
-
router.forward(),
|
|
141
|
-
// First operation succeeds
|
|
142
|
-
router.forward()
|
|
143
|
-
// Second operation returns null
|
|
144
|
-
]);
|
|
145
|
-
expect(firstResult == null ? void 0 : firstResult.handle).not.toBeNull();
|
|
146
|
-
expect(secondResult).toBe(null);
|
|
147
|
-
expect(updateSpy).toHaveBeenCalledTimes(1);
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
describe("\u{1F3AD} Micro-app Integration", () => {
|
|
151
|
-
test("forward should trigger micro-app update", async () => {
|
|
152
|
-
const updateSpy = vi.spyOn(router.microApp, "_update");
|
|
153
|
-
await router.push("/about");
|
|
154
|
-
await router.back();
|
|
155
|
-
await router.forward();
|
|
156
|
-
expect(updateSpy).toHaveBeenCalled();
|
|
157
|
-
});
|
|
158
|
-
test("micro-app update should happen after route state update", async () => {
|
|
159
|
-
let routePathWhenUpdated = null;
|
|
160
|
-
vi.spyOn(router.microApp, "_update").mockImplementation(() => {
|
|
161
|
-
routePathWhenUpdated = router.route.path;
|
|
162
|
-
});
|
|
163
|
-
await router.push("/about");
|
|
164
|
-
await router.back();
|
|
165
|
-
await router.forward();
|
|
166
|
-
expect(routePathWhenUpdated).toBe("/about");
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
describe("\u26A1 Async Components & Forward", () => {
|
|
170
|
-
test("forward to async component route should wait for component loading", async () => {
|
|
171
|
-
await router.push("/async");
|
|
172
|
-
await router.back();
|
|
173
|
-
const route = await router.forward();
|
|
174
|
-
expect(route == null ? void 0 : route.path).toBe("/async");
|
|
175
|
-
expect(route == null ? void 0 : route.handle).not.toBeNull();
|
|
176
|
-
});
|
|
177
|
-
test("forward to failed async component route should return error status", async () => {
|
|
178
|
-
await router.push("/about");
|
|
179
|
-
await expect(router.push("/async-error")).rejects.toThrow();
|
|
180
|
-
expect(router.route.path).toBe("/about");
|
|
181
|
-
const route = await router.forward();
|
|
182
|
-
expect(route).toBe(null);
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
|
-
describe("\u{1F6E1}\uFE0F Forward Guard Behavior", () => {
|
|
186
|
-
test("forward to guard-blocked route should throw navigation aborted error", async () => {
|
|
187
|
-
await expect(router.push("/user/blocked")).rejects.toThrow();
|
|
188
|
-
expect(router.route.path).toBe("/");
|
|
189
|
-
const result = await router.forward();
|
|
190
|
-
expect(result).toBe(null);
|
|
191
|
-
});
|
|
192
|
-
test("forward to route with redirect guard should navigate to redirect route", async () => {
|
|
193
|
-
await router.push("/user/redirect");
|
|
194
|
-
await router.back();
|
|
195
|
-
const route = await router.forward();
|
|
196
|
-
expect(route == null ? void 0 : route.path).toBe("/about");
|
|
197
|
-
});
|
|
198
|
-
test("afterEach only executes when forward succeeds", async () => {
|
|
199
|
-
let afterEachCalled = false;
|
|
200
|
-
const testRouter = new Router({
|
|
201
|
-
mode: RouterMode.memory,
|
|
202
|
-
base: new URL("http://localhost:3000/"),
|
|
203
|
-
routes: [
|
|
204
|
-
{ path: "/", component: "Home" },
|
|
205
|
-
{ path: "/about", component: "About" },
|
|
206
|
-
{
|
|
207
|
-
path: "/blocked",
|
|
208
|
-
component: "Blocked",
|
|
209
|
-
beforeEnter: () => false
|
|
210
|
-
}
|
|
211
|
-
]
|
|
212
|
-
});
|
|
213
|
-
testRouter.afterEach(() => {
|
|
214
|
-
afterEachCalled = true;
|
|
215
|
-
});
|
|
216
|
-
await testRouter.push("/about");
|
|
217
|
-
afterEachCalled = false;
|
|
218
|
-
await testRouter.back();
|
|
219
|
-
afterEachCalled = false;
|
|
220
|
-
await testRouter.forward();
|
|
221
|
-
expect(afterEachCalled).toBe(true);
|
|
222
|
-
testRouter.destroy();
|
|
223
|
-
});
|
|
224
|
-
test("beforeEach guard should be called during forward operation", async () => {
|
|
225
|
-
let beforeEachCalled = false;
|
|
226
|
-
router.beforeEach(() => {
|
|
227
|
-
beforeEachCalled = true;
|
|
228
|
-
});
|
|
229
|
-
await router.push("/about");
|
|
230
|
-
await router.back();
|
|
231
|
-
await router.forward();
|
|
232
|
-
expect(beforeEachCalled).toBe(true);
|
|
233
|
-
});
|
|
234
|
-
});
|
|
235
|
-
describe("\u{1F4BE} History Management", () => {
|
|
236
|
-
test("forward should navigate correctly in history stack", async () => {
|
|
237
|
-
await router.push("/about");
|
|
238
|
-
await router.push("/user/123");
|
|
239
|
-
await router.back();
|
|
240
|
-
const route = await router.forward();
|
|
241
|
-
expect(route == null ? void 0 : route.path).toBe("/user/123");
|
|
242
|
-
expect(router.route.path).toBe("/user/123");
|
|
243
|
-
});
|
|
244
|
-
test("forward operation should not create new history entries", async () => {
|
|
245
|
-
await router.push("/about");
|
|
246
|
-
await router.push("/user/123");
|
|
247
|
-
await router.back();
|
|
248
|
-
await router.forward();
|
|
249
|
-
const backRoute = await router.back();
|
|
250
|
-
expect(backRoute == null ? void 0 : backRoute.path).toBe("/about");
|
|
251
|
-
});
|
|
252
|
-
});
|
|
253
|
-
describe("\u274C Error Handling", () => {
|
|
254
|
-
test("forward to non-existent route should trigger location handling", async () => {
|
|
255
|
-
const fallbackSpy = vi.fn();
|
|
256
|
-
const testRouter = new Router({
|
|
257
|
-
mode: RouterMode.memory,
|
|
258
|
-
base: new URL("http://localhost:3000/"),
|
|
259
|
-
fallback: fallbackSpy,
|
|
260
|
-
routes: [{ path: "/", component: "Home" }]
|
|
261
|
-
});
|
|
262
|
-
await testRouter.push("/");
|
|
263
|
-
const result = await testRouter.forward();
|
|
264
|
-
expect(result).toBe(null);
|
|
265
|
-
testRouter.destroy();
|
|
266
|
-
});
|
|
267
|
-
test("exceptions during forward process should propagate correctly", async () => {
|
|
268
|
-
const testRouter = new Router({
|
|
269
|
-
mode: RouterMode.memory,
|
|
270
|
-
base: new URL("http://localhost:3000/"),
|
|
271
|
-
routes: [
|
|
272
|
-
{ path: "/", component: "Home" },
|
|
273
|
-
{ path: "/about", component: "About" }
|
|
274
|
-
]
|
|
275
|
-
});
|
|
276
|
-
await testRouter.push("/about");
|
|
277
|
-
await testRouter.back();
|
|
278
|
-
testRouter.beforeEach(() => {
|
|
279
|
-
throw new Error("Guard error");
|
|
280
|
-
});
|
|
281
|
-
await expect(testRouter.forward()).rejects.toThrow("Guard error");
|
|
282
|
-
testRouter.destroy();
|
|
283
|
-
});
|
|
284
|
-
});
|
|
285
|
-
describe("\u{1F50D} Edge Cases", () => {
|
|
286
|
-
test("forward should handle special character paths correctly", async () => {
|
|
287
|
-
const testRouter = new Router({
|
|
288
|
-
mode: RouterMode.memory,
|
|
289
|
-
base: new URL("http://localhost:3000/"),
|
|
290
|
-
routes: [
|
|
291
|
-
{ path: "/", component: "Home" },
|
|
292
|
-
{ path: "/special", component: "Special" }
|
|
293
|
-
],
|
|
294
|
-
fallback: () => ({ component: "Fallback" })
|
|
295
|
-
});
|
|
296
|
-
await testRouter.push("/");
|
|
297
|
-
await testRouter.push("/special");
|
|
298
|
-
expect(testRouter.route.path).toBe("/special");
|
|
299
|
-
await testRouter.back();
|
|
300
|
-
expect(testRouter.route.path).toBe("/");
|
|
301
|
-
const route = await testRouter.forward();
|
|
302
|
-
expect(route == null ? void 0 : route.path).toBe("/special");
|
|
303
|
-
expect(testRouter.route.path).toBe("/special");
|
|
304
|
-
testRouter.destroy();
|
|
305
|
-
});
|
|
306
|
-
});
|
|
307
|
-
describe("\u{1F517} Integration with Other Navigation Methods", () => {
|
|
308
|
-
test("forward should behave consistently with go(1)", async () => {
|
|
309
|
-
await router.push("/about");
|
|
310
|
-
await router.push("/user/123");
|
|
311
|
-
await router.back();
|
|
312
|
-
await router.back();
|
|
313
|
-
const forwardRoute = await router.forward();
|
|
314
|
-
const goRoute = await router.go(1);
|
|
315
|
-
expect(forwardRoute == null ? void 0 : forwardRoute.path).toBe("/about");
|
|
316
|
-
expect(goRoute == null ? void 0 : goRoute.path).toBe("/user/123");
|
|
317
|
-
});
|
|
318
|
-
test("push after forward should handle history correctly", async () => {
|
|
319
|
-
await router.push("/about");
|
|
320
|
-
await router.push("/user/123");
|
|
321
|
-
await router.back();
|
|
322
|
-
await router.forward();
|
|
323
|
-
await router.push("/user/456");
|
|
324
|
-
expect(router.route.path).toBe("/user/456");
|
|
325
|
-
});
|
|
326
|
-
});
|
|
327
|
-
describe("\u{1F527} handleBackBoundary Callback Tests", () => {
|
|
328
|
-
test("forward beyond boundaries should not trigger handleBackBoundary", async () => {
|
|
329
|
-
let handleBackBoundaryCalled = false;
|
|
330
|
-
const testRouter = new Router({
|
|
331
|
-
mode: RouterMode.memory,
|
|
332
|
-
base: new URL("http://localhost:3000/"),
|
|
333
|
-
routes: [{ path: "/", component: "Home" }],
|
|
334
|
-
handleBackBoundary: () => {
|
|
335
|
-
handleBackBoundaryCalled = true;
|
|
336
|
-
}
|
|
337
|
-
});
|
|
338
|
-
await testRouter.push("/");
|
|
339
|
-
const result = await testRouter.forward();
|
|
340
|
-
expect(result).toBe(null);
|
|
341
|
-
expect(handleBackBoundaryCalled).toBe(false);
|
|
342
|
-
testRouter.destroy();
|
|
343
|
-
});
|
|
344
|
-
test("should not error when no handleBackBoundary callback", async () => {
|
|
345
|
-
const testRouter = new Router({
|
|
346
|
-
mode: RouterMode.memory,
|
|
347
|
-
base: new URL("http://localhost:3000/"),
|
|
348
|
-
routes: [{ path: "/", component: "Home" }]
|
|
349
|
-
});
|
|
350
|
-
await testRouter.push("/");
|
|
351
|
-
const result = await testRouter.forward();
|
|
352
|
-
expect(result).toBe(null);
|
|
353
|
-
testRouter.destroy();
|
|
354
|
-
});
|
|
355
|
-
});
|
|
356
|
-
describe("\u{1F504} Navigation Result Handling", () => {
|
|
357
|
-
test("should correctly handle successful navigation result", async () => {
|
|
358
|
-
await router.push("/about");
|
|
359
|
-
await router.back();
|
|
360
|
-
const route = await router.forward();
|
|
361
|
-
expect(route == null ? void 0 : route.path).toBe("/about");
|
|
362
|
-
expect(router.route.path).toBe("/about");
|
|
363
|
-
});
|
|
364
|
-
test("should return null directly when Navigation returns null", async () => {
|
|
365
|
-
const testRouter = new Router({
|
|
366
|
-
mode: RouterMode.memory,
|
|
367
|
-
base: new URL("http://localhost:3000/"),
|
|
368
|
-
routes: [{ path: "/", component: "Home" }]
|
|
369
|
-
});
|
|
370
|
-
await testRouter.push("/");
|
|
371
|
-
const result = await testRouter.forward();
|
|
372
|
-
expect(result).toBe(null);
|
|
373
|
-
testRouter.destroy();
|
|
374
|
-
});
|
|
375
|
-
});
|
|
376
|
-
});
|
package/dist/router-go.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/router-go.test.mjs
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
|
2
|
-
import { Router } from "./router.mjs";
|
|
3
|
-
import { RouterMode } from "./types.mjs";
|
|
4
|
-
describe("Router Go Tests", () => {
|
|
5
|
-
let router;
|
|
6
|
-
beforeEach(async () => {
|
|
7
|
-
router = new Router({
|
|
8
|
-
mode: RouterMode.memory,
|
|
9
|
-
base: new URL("http://localhost:3000/"),
|
|
10
|
-
routes: [
|
|
11
|
-
{ path: "/", component: () => "Home" },
|
|
12
|
-
{ path: "/user/:id", component: () => "User" },
|
|
13
|
-
{ path: "/about", component: () => "About" }
|
|
14
|
-
]
|
|
15
|
-
});
|
|
16
|
-
await router.replace("/");
|
|
17
|
-
});
|
|
18
|
-
afterEach(() => {
|
|
19
|
-
router.destroy();
|
|
20
|
-
});
|
|
21
|
-
describe("Basic go navigation", () => {
|
|
22
|
-
test("should go back successfully", async () => {
|
|
23
|
-
await router.push("/about");
|
|
24
|
-
await router.push("/user/123");
|
|
25
|
-
const route = await router.go(-1);
|
|
26
|
-
expect(route == null ? void 0 : route.path).toBe("/about");
|
|
27
|
-
expect(router.route.path).toBe("/about");
|
|
28
|
-
});
|
|
29
|
-
test("should go forward successfully", async () => {
|
|
30
|
-
await router.push("/about");
|
|
31
|
-
await router.push("/user/123");
|
|
32
|
-
await router.back();
|
|
33
|
-
const route = await router.go(1);
|
|
34
|
-
expect(route == null ? void 0 : route.path).toBe("/user/123");
|
|
35
|
-
expect(router.route.path).toBe("/user/123");
|
|
36
|
-
});
|
|
37
|
-
test("should handle go to specific position", async () => {
|
|
38
|
-
await router.push("/about");
|
|
39
|
-
await router.push("/user/123");
|
|
40
|
-
await router.push("/user/456");
|
|
41
|
-
const route = await router.go(-2);
|
|
42
|
-
expect(route == null ? void 0 : route.path).toBe("/about");
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
describe("Error handling", () => {
|
|
46
|
-
test("should handle go when history is empty", async () => {
|
|
47
|
-
const route = await router.go(-1);
|
|
48
|
-
expect(route).toBe(null);
|
|
49
|
-
const route2 = await router.go(1);
|
|
50
|
-
expect(route2).toBe(null);
|
|
51
|
-
});
|
|
52
|
-
test("should handle invalid delta values", async () => {
|
|
53
|
-
const route = await router.go(0);
|
|
54
|
-
expect(route).toBe(null);
|
|
55
|
-
const route2 = await router.go(-10);
|
|
56
|
-
expect(route2).toBe(null);
|
|
57
|
-
});
|
|
58
|
-
});
|
|
59
|
-
describe("History boundaries", () => {
|
|
60
|
-
test("should return null when going beyond history", async () => {
|
|
61
|
-
const route = await router.go(-10);
|
|
62
|
-
expect(route).toBe(null);
|
|
63
|
-
const route2 = await router.go(10);
|
|
64
|
-
expect(route2).toBe(null);
|
|
65
|
-
});
|
|
66
|
-
test("should handle boundary conditions gracefully", async () => {
|
|
67
|
-
await router.push("/about");
|
|
68
|
-
const route = await router.go(-2);
|
|
69
|
-
expect(route).toBe(null);
|
|
70
|
-
expect(router.route.path).toBe("/about");
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|