@esmx/router 3.0.0-rc.27 → 3.0.0-rc.30

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.
Files changed (59) hide show
  1. package/README.zh-CN.md +82 -1
  2. package/dist/index.d.ts +1 -2
  3. package/dist/index.mjs +0 -1
  4. package/package.json +4 -4
  5. package/src/index.ts +0 -3
  6. package/dist/index.test.d.ts +0 -1
  7. package/dist/index.test.mjs +0 -8
  8. package/dist/location.test.d.ts +0 -8
  9. package/dist/location.test.mjs +0 -370
  10. package/dist/matcher.test.d.ts +0 -1
  11. package/dist/matcher.test.mjs +0 -1492
  12. package/dist/micro-app.dom.test.d.ts +0 -1
  13. package/dist/micro-app.dom.test.mjs +0 -532
  14. package/dist/navigation.test.d.ts +0 -1
  15. package/dist/navigation.test.mjs +0 -681
  16. package/dist/route-task.test.d.ts +0 -1
  17. package/dist/route-task.test.mjs +0 -673
  18. package/dist/route-transition.test.d.ts +0 -1
  19. package/dist/route-transition.test.mjs +0 -146
  20. package/dist/route.test.d.ts +0 -1
  21. package/dist/route.test.mjs +0 -1664
  22. package/dist/router-back.test.d.ts +0 -1
  23. package/dist/router-back.test.mjs +0 -361
  24. package/dist/router-forward.test.d.ts +0 -1
  25. package/dist/router-forward.test.mjs +0 -376
  26. package/dist/router-go.test.d.ts +0 -1
  27. package/dist/router-go.test.mjs +0 -73
  28. package/dist/router-guards-cleanup.test.d.ts +0 -1
  29. package/dist/router-guards-cleanup.test.mjs +0 -437
  30. package/dist/router-push.test.d.ts +0 -1
  31. package/dist/router-push.test.mjs +0 -115
  32. package/dist/router-replace.test.d.ts +0 -1
  33. package/dist/router-replace.test.mjs +0 -114
  34. package/dist/router-resolve.test.d.ts +0 -1
  35. package/dist/router-resolve.test.mjs +0 -393
  36. package/dist/router-restart-app.dom.test.d.ts +0 -1
  37. package/dist/router-restart-app.dom.test.mjs +0 -616
  38. package/dist/router-window-navigation.test.d.ts +0 -1
  39. package/dist/router-window-navigation.test.mjs +0 -359
  40. package/dist/util.test.d.ts +0 -1
  41. package/dist/util.test.mjs +0 -1020
  42. package/src/index.test.ts +0 -9
  43. package/src/location.test.ts +0 -406
  44. package/src/matcher.test.ts +0 -1685
  45. package/src/micro-app.dom.test.ts +0 -708
  46. package/src/navigation.test.ts +0 -858
  47. package/src/route-task.test.ts +0 -901
  48. package/src/route-transition.test.ts +0 -178
  49. package/src/route.test.ts +0 -2014
  50. package/src/router-back.test.ts +0 -487
  51. package/src/router-forward.test.ts +0 -506
  52. package/src/router-go.test.ts +0 -91
  53. package/src/router-guards-cleanup.test.ts +0 -595
  54. package/src/router-push.test.ts +0 -140
  55. package/src/router-replace.test.ts +0 -139
  56. package/src/router-resolve.test.ts +0 -475
  57. package/src/router-restart-app.dom.test.ts +0 -783
  58. package/src/router-window-navigation.test.ts +0 -457
  59. package/src/util.test.ts +0 -1262
@@ -1,1020 +0,0 @@
1
- import { describe, expect, test } from "vitest";
2
- import { parsedOptions } from "./options.mjs";
3
- import { Route } from "./route.mjs";
4
- import { RouteType } from "./types.mjs";
5
- import {
6
- isNonEmptyPlainObject,
7
- isNotNullish,
8
- isPlainObject,
9
- isRouteMatched,
10
- isUrlEqual,
11
- isValidConfirmHookResult,
12
- removeFromArray
13
- } from "./util.mjs";
14
- const AsyncFunction = (async () => {
15
- }).constructor;
16
- describe("isNotNullish", () => {
17
- test("should return true for non-nullish values", () => {
18
- expect(isNotNullish(null)).toBe(false);
19
- expect(isNotNullish(void 0)).toBe(false);
20
- expect(isNotNullish(+"a")).toBe(false);
21
- expect(isNotNullish(Number.NaN)).toBe(false);
22
- expect(isNotNullish(Number("a"))).toBe(false);
23
- expect(isNotNullish(new Number("a"))).toBe(false);
24
- expect(isNotNullish(0)).toBe(true);
25
- expect(isNotNullish(123)).toBe(true);
26
- expect(isNotNullish(/* @__PURE__ */ BigInt("123"))).toBe(true);
27
- expect(isNotNullish(/* @__PURE__ */ BigInt("0"))).toBe(true);
28
- expect(isNotNullish(new Number("1"))).toBe(true);
29
- expect(isNotNullish(Number.POSITIVE_INFINITY)).toBe(true);
30
- expect(isNotNullish(Number.NEGATIVE_INFINITY)).toBe(true);
31
- expect(isNotNullish(Number.EPSILON)).toBe(true);
32
- expect(isNotNullish("")).toBe(true);
33
- expect(isNotNullish("0")).toBe(true);
34
- expect(isNotNullish("1")).toBe(true);
35
- expect(isNotNullish("test")).toBe(true);
36
- expect(isNotNullish(new String(""))).toBe(true);
37
- expect(isNotNullish(new String("0"))).toBe(true);
38
- expect(isNotNullish(new String("1"))).toBe(true);
39
- expect(isNotNullish(new String("test"))).toBe(true);
40
- expect(isNotNullish(true)).toBe(true);
41
- expect(isNotNullish(false)).toBe(true);
42
- expect(isNotNullish(new Boolean(true))).toBe(true);
43
- expect(isNotNullish(new Boolean(false))).toBe(true);
44
- expect(isNotNullish({})).toBe(true);
45
- expect(isNotNullish({ key: "value" })).toBe(true);
46
- expect(isNotNullish(new Object())).toBe(true);
47
- expect(isNotNullish(/* @__PURE__ */ Object.create(null))).toBe(true);
48
- expect(isNotNullish(/* @__PURE__ */ Object.create({}))).toBe(true);
49
- expect(isNotNullish(Object.create(Object.prototype))).toBe(true);
50
- expect(isNotNullish({ __proto__: null })).toBe(true);
51
- expect(isNotNullish({ [Symbol.toStringTag]: "Tag" })).toBe(true);
52
- expect(isNotNullish({ toString: () => "[object CustomObject]" })).toBe(
53
- true
54
- );
55
- expect(isNotNullish([])).toBe(true);
56
- expect(isNotNullish(["a", "b"])).toBe(true);
57
- expect(isNotNullish(new Array())).toBe(true);
58
- expect(isNotNullish(new Array(1, 2, 3))).toBe(true);
59
- expect(isNotNullish(new Array(1))).toBe(true);
60
- expect(isNotNullish(new Uint8Array(8))).toBe(true);
61
- expect(isNotNullish(new ArrayBuffer(8))).toBe(true);
62
- expect(isNotNullish(new DataView(new ArrayBuffer(8)))).toBe(true);
63
- expect(isNotNullish(() => {
64
- })).toBe(true);
65
- expect(isNotNullish(async () => {
66
- })).toBe(true);
67
- expect(isNotNullish(new Function("return 1;"))).toBe(true);
68
- expect(isNotNullish(AsyncFunction("return 1;"))).toBe(true);
69
- expect(isNotNullish(/* @__PURE__ */ new Date())).toBe(true);
70
- expect(isNotNullish(Symbol("test"))).toBe(true);
71
- expect(isNotNullish(/* @__PURE__ */ new Map())).toBe(true);
72
- expect(isNotNullish(/* @__PURE__ */ new Set())).toBe(true);
73
- expect(isNotNullish(/* @__PURE__ */ new WeakMap())).toBe(true);
74
- expect(isNotNullish(/* @__PURE__ */ new WeakSet())).toBe(true);
75
- expect(isNotNullish(/test/)).toBe(true);
76
- expect(isNotNullish(new Error("test"))).toBe(true);
77
- expect(isNotNullish(Promise.resolve())).toBe(true);
78
- expect(isNotNullish(new URL("https://example.com"))).toBe(true);
79
- expect(isNotNullish(new URLSearchParams("key=value"))).toBe(true);
80
- expect(isNotNullish(new Blob(["test"]))).toBe(true);
81
- expect(isNotNullish(new File(["test"], "file.txt"))).toBe(true);
82
- expect(isNotNullish(Math)).toBe(true);
83
- expect(isNotNullish(JSON)).toBe(true);
84
- expect(isNotNullish(console)).toBe(true);
85
- });
86
- test("should handle edge cases with Number constructor", () => {
87
- expect(isNotNullish(Number())).toBe(true);
88
- expect(isNotNullish(Number(void 0))).toBe(false);
89
- expect(isNotNullish(Number(null))).toBe(true);
90
- expect(isNotNullish(Number(""))).toBe(true);
91
- expect(isNotNullish(Number("0"))).toBe(true);
92
- expect(isNotNullish(Number("123"))).toBe(true);
93
- expect(isNotNullish(new Number())).toBe(true);
94
- expect(isNotNullish(new Number(void 0))).toBe(false);
95
- expect(isNotNullish(new Number(null))).toBe(true);
96
- expect(isNotNullish(new Number(""))).toBe(true);
97
- expect(isNotNullish(new Number("0"))).toBe(true);
98
- expect(isNotNullish(new Number("123"))).toBe(true);
99
- });
100
- test("should handle various NaN cases", () => {
101
- expect(isNotNullish(0 / 0)).toBe(false);
102
- expect(isNotNullish(Math.sqrt(-1))).toBe(false);
103
- expect(isNotNullish(Number.parseInt("abc"))).toBe(false);
104
- expect(isNotNullish(Number.parseFloat("abc"))).toBe(false);
105
- expect(isNotNullish(Number.NaN)).toBe(false);
106
- expect(isNotNullish(Number.NaN)).toBe(false);
107
- expect(isNotNullish(new Number(Number.NaN))).toBe(false);
108
- expect(isNotNullish(new Number(0 / 0))).toBe(false);
109
- expect(isNotNullish(new Number(Number.parseInt("abc")))).toBe(false);
110
- });
111
- test("should handle complex objects", () => {
112
- class CustomClass {
113
- constructor(value) {
114
- this.value = value;
115
- }
116
- }
117
- expect(isNotNullish(new CustomClass(123))).toBe(true);
118
- const frozenObj = Object.freeze({ a: 1 });
119
- const sealedObj = Object.seal({ b: 2 });
120
- expect(isNotNullish(frozenObj)).toBe(true);
121
- expect(isNotNullish(sealedObj)).toBe(true);
122
- const objWithDescriptor = {};
123
- Object.defineProperty(objWithDescriptor, "prop", {
124
- value: "test",
125
- writable: false
126
- });
127
- expect(isNotNullish(objWithDescriptor)).toBe(true);
128
- });
129
- });
130
- describe("isPlainObject", () => {
131
- test("should return true for plain objects", () => {
132
- expect(isPlainObject({})).toBe(true);
133
- expect(isPlainObject({ key: "value" })).toBe(true);
134
- expect(isPlainObject(new Object())).toBe(true);
135
- expect(isPlainObject(/* @__PURE__ */ Object.create(null))).toBe(true);
136
- expect(isPlainObject(/* @__PURE__ */ Object.create({}))).toBe(true);
137
- expect(isPlainObject(Object.create(Object.prototype))).toBe(true);
138
- expect(isPlainObject(/* @__PURE__ */ Object.create({ parent: "value" }))).toBe(true);
139
- expect(isPlainObject({ __proto__: null })).toBe(true);
140
- expect(isPlainObject({ [Symbol.toStringTag]: "Tag" })).toBe(true);
141
- expect(isPlainObject({ toString: () => "[object CustomObject]" })).toBe(
142
- true
143
- );
144
- expect(isPlainObject(Math)).toBe(true);
145
- expect(isPlainObject(JSON)).toBe(true);
146
- class TestClass {
147
- }
148
- expect(isPlainObject(new TestClass())).toBe(true);
149
- });
150
- test("should return false for non-plain objects", () => {
151
- expect(isPlainObject(null)).toBe(false);
152
- expect(isPlainObject(void 0)).toBe(false);
153
- expect(isPlainObject([])).toBe(false);
154
- expect(isPlainObject(["a", "b"])).toBe(false);
155
- expect(isPlainObject(new Array())).toBe(false);
156
- expect(isPlainObject(new Array(1, 2, 3))).toBe(false);
157
- expect(isPlainObject(new Array(1))).toBe(false);
158
- expect(isPlainObject(new Uint8Array(8))).toBe(false);
159
- expect(isPlainObject(new ArrayBuffer(8))).toBe(false);
160
- expect(isPlainObject(new DataView(new ArrayBuffer(8)))).toBe(false);
161
- expect(isPlainObject("")).toBe(false);
162
- expect(isPlainObject("0")).toBe(false);
163
- expect(isPlainObject("1")).toBe(false);
164
- expect(isPlainObject("string")).toBe(false);
165
- expect(isPlainObject(new String(""))).toBe(false);
166
- expect(isPlainObject(new String("0"))).toBe(false);
167
- expect(isPlainObject(new String("1"))).toBe(false);
168
- expect(isPlainObject(new String("string"))).toBe(false);
169
- expect(isPlainObject(true)).toBe(false);
170
- expect(isPlainObject(false)).toBe(false);
171
- expect(isPlainObject(new Boolean(true))).toBe(false);
172
- expect(isPlainObject(new Boolean(false))).toBe(false);
173
- expect(isPlainObject(0)).toBe(false);
174
- expect(isPlainObject(/* @__PURE__ */ BigInt("0"))).toBe(false);
175
- expect(isPlainObject(123)).toBe(false);
176
- expect(isPlainObject(/* @__PURE__ */ BigInt("123"))).toBe(false);
177
- expect(isPlainObject(new Number("1"))).toBe(false);
178
- expect(isPlainObject(+"a")).toBe(false);
179
- expect(isPlainObject(Number.NaN)).toBe(false);
180
- expect(isPlainObject(new Number("a"))).toBe(false);
181
- expect(isPlainObject(() => {
182
- })).toBe(false);
183
- expect(isPlainObject(async () => {
184
- })).toBe(false);
185
- expect(isPlainObject(new Function("return 1;"))).toBe(false);
186
- expect(isPlainObject(AsyncFunction("return 1;"))).toBe(false);
187
- expect(isPlainObject(/* @__PURE__ */ new Date())).toBe(false);
188
- expect(isPlainObject(Symbol("test"))).toBe(false);
189
- expect(isPlainObject(/* @__PURE__ */ new Map())).toBe(false);
190
- expect(isPlainObject(/* @__PURE__ */ new Set())).toBe(false);
191
- expect(isPlainObject(/* @__PURE__ */ new WeakMap())).toBe(false);
192
- expect(isPlainObject(/* @__PURE__ */ new WeakSet())).toBe(false);
193
- expect(isPlainObject(/test/)).toBe(false);
194
- expect(isPlainObject(new Error("test"))).toBe(false);
195
- expect(isPlainObject(Promise.resolve())).toBe(false);
196
- expect(isPlainObject(new URL("https://example.com"))).toBe(false);
197
- expect(isPlainObject(new URLSearchParams("key=value"))).toBe(false);
198
- expect(isPlainObject(new Blob(["test"]))).toBe(false);
199
- expect(isPlainObject(new File(["test"], "file.txt"))).toBe(false);
200
- });
201
- test("should distinguish between objects and boxed primitives", () => {
202
- expect(isPlainObject(Object(42))).toBe(false);
203
- expect(isPlainObject(Object("str"))).toBe(false);
204
- expect(isPlainObject(Object(true))).toBe(false);
205
- expect(isPlainObject(Object(Symbol("sym")))).toBe(false);
206
- });
207
- });
208
- describe("isNonEmptyPlainObject", () => {
209
- test("should return true for non-empty plain objects", () => {
210
- expect(isNonEmptyPlainObject({ key: "value" })).toBe(true);
211
- expect(isNonEmptyPlainObject({ a: 1, b: 2 })).toBe(true);
212
- expect(isNonEmptyPlainObject({ nested: { value: "test" } })).toBe(true);
213
- expect(
214
- isNonEmptyPlainObject({ toString: () => "[object CustomObject]" })
215
- ).toBe(true);
216
- const obj = new Object();
217
- obj.prop = "value";
218
- expect(isNonEmptyPlainObject(obj)).toBe(true);
219
- const objWithProto = /* @__PURE__ */ Object.create({ parent: "value" });
220
- objWithProto.own = "property";
221
- expect(isNonEmptyPlainObject(objWithProto)).toBe(true);
222
- class TestClass {
223
- }
224
- const instance = new TestClass();
225
- instance.prop = "value";
226
- expect(isNonEmptyPlainObject(instance)).toBe(true);
227
- });
228
- test("should return false for empty objects", () => {
229
- expect(isNonEmptyPlainObject({})).toBe(false);
230
- expect(isNonEmptyPlainObject(new Object())).toBe(false);
231
- expect(isNonEmptyPlainObject(/* @__PURE__ */ Object.create(null))).toBe(false);
232
- expect(isNonEmptyPlainObject(/* @__PURE__ */ Object.create({}))).toBe(false);
233
- expect(isNonEmptyPlainObject(Object.create(Object.prototype))).toBe(
234
- false
235
- );
236
- expect(isNonEmptyPlainObject({ __proto__: null })).toBe(false);
237
- class TestClass {
238
- }
239
- expect(isNonEmptyPlainObject(new TestClass())).toBe(false);
240
- expect(isNonEmptyPlainObject({ [Symbol.toStringTag]: "Tag" })).toBe(
241
- false
242
- );
243
- expect(isNonEmptyPlainObject({ [Symbol("key")]: "value" })).toBe(false);
244
- });
245
- test("should return false for non-objects", () => {
246
- expect(isNonEmptyPlainObject(null)).toBe(false);
247
- expect(isNonEmptyPlainObject(void 0)).toBe(false);
248
- expect(isNonEmptyPlainObject("")).toBe(false);
249
- expect(isNonEmptyPlainObject("non-empty")).toBe(false);
250
- expect(isNonEmptyPlainObject(0)).toBe(false);
251
- expect(isNonEmptyPlainObject(123)).toBe(false);
252
- expect(isNonEmptyPlainObject(/* @__PURE__ */ BigInt("0"))).toBe(false);
253
- expect(isNonEmptyPlainObject(/* @__PURE__ */ BigInt("123"))).toBe(false);
254
- expect(isNonEmptyPlainObject(true)).toBe(false);
255
- expect(isNonEmptyPlainObject(false)).toBe(false);
256
- expect(isNonEmptyPlainObject(Symbol("test"))).toBe(false);
257
- expect(isNonEmptyPlainObject([])).toBe(false);
258
- expect(isNonEmptyPlainObject(["a", "b"])).toBe(false);
259
- expect(isNonEmptyPlainObject(() => {
260
- })).toBe(false);
261
- expect(isNonEmptyPlainObject(async () => {
262
- })).toBe(false);
263
- expect(isNonEmptyPlainObject(/* @__PURE__ */ new Date())).toBe(false);
264
- expect(isNonEmptyPlainObject(/* @__PURE__ */ new Map())).toBe(false);
265
- expect(isNonEmptyPlainObject(/* @__PURE__ */ new Set())).toBe(false);
266
- expect(isNonEmptyPlainObject(/test/)).toBe(false);
267
- expect(isNonEmptyPlainObject(new Error("test"))).toBe(false);
268
- expect(isNonEmptyPlainObject(Promise.resolve())).toBe(false);
269
- expect(isNonEmptyPlainObject(new String("test"))).toBe(false);
270
- expect(isNonEmptyPlainObject(new Number(123))).toBe(false);
271
- expect(isNonEmptyPlainObject(new Boolean(true))).toBe(false);
272
- });
273
- test("should handle objects with only inherited properties", () => {
274
- const parentObj = { parentProp: "value" };
275
- const childObj = Object.create(parentObj);
276
- expect(isNonEmptyPlainObject(childObj)).toBe(false);
277
- childObj.ownProp = "own";
278
- expect(isNonEmptyPlainObject(childObj)).toBe(true);
279
- });
280
- test("should handle edge cases", () => {
281
- const objWithNonEnum = {};
282
- Object.defineProperty(objWithNonEnum, "nonEnum", {
283
- value: "hidden",
284
- enumerable: false
285
- });
286
- expect(isNonEmptyPlainObject(objWithNonEnum)).toBe(false);
287
- Object.defineProperty(objWithNonEnum, "visible", {
288
- value: "visible",
289
- enumerable: true
290
- });
291
- expect(isNonEmptyPlainObject(objWithNonEnum)).toBe(true);
292
- const frozenObj = Object.freeze({ prop: "value" });
293
- expect(isNonEmptyPlainObject(frozenObj)).toBe(true);
294
- const sealedObj = Object.seal({ prop: "value" });
295
- expect(isNonEmptyPlainObject(sealedObj)).toBe(true);
296
- });
297
- });
298
- describe("removeFromArray", () => {
299
- test("should remove first occurrence when duplicates exist", () => {
300
- const arr = [1, 2, 2, 3];
301
- removeFromArray(arr, 2);
302
- expect(arr).toEqual([1, 2, 3]);
303
- const num = new Number(2);
304
- let arrWithObj = [1, num, 2, 3];
305
- removeFromArray(arrWithObj, 2);
306
- expect(arrWithObj).toEqual([1, num, 3]);
307
- arrWithObj = [1, num, 2, 3];
308
- removeFromArray(arrWithObj, num);
309
- expect(arrWithObj).toEqual([1, 2, 3]);
310
- arrWithObj = [1, 2, num, 3];
311
- removeFromArray(arrWithObj, num);
312
- expect(arrWithObj).toEqual([1, 2, 3]);
313
- arrWithObj = [1, 2, num, 3];
314
- removeFromArray(arrWithObj, 2);
315
- expect(arrWithObj).toEqual([1, num, 3]);
316
- arrWithObj = [1, num, num, 3];
317
- removeFromArray(arrWithObj, num);
318
- expect(arrWithObj).toEqual([1, num, 3]);
319
- });
320
- test("should remove existing element from array", () => {
321
- const arr = [1, 2, 3];
322
- removeFromArray(arr, 2);
323
- expect(arr).toEqual([1, 3]);
324
- });
325
- test("should do nothing when element not found", () => {
326
- const arr = [1, 2, 3];
327
- removeFromArray(arr, 4);
328
- expect(arr).toEqual([1, 2, 3]);
329
- });
330
- test("should work with object references", () => {
331
- const obj1 = { id: 1 };
332
- const obj2 = { id: 2 };
333
- const arr = [obj1, obj2];
334
- removeFromArray(arr, obj1);
335
- expect(arr).toEqual([obj2]);
336
- });
337
- test("should handle edge cases", () => {
338
- const emptyArr = [];
339
- removeFromArray(emptyArr, 1);
340
- expect(emptyArr).toEqual([]);
341
- const singleArr = [42];
342
- removeFromArray(singleArr, 42);
343
- expect(singleArr).toEqual([]);
344
- const singleArr2 = [42];
345
- removeFromArray(singleArr2, 99);
346
- expect(singleArr2).toEqual([42]);
347
- const sameArr = [5, 5, 5, 5];
348
- removeFromArray(sameArr, 5);
349
- expect(sameArr).toEqual([5, 5, 5]);
350
- const nullishArr = [1, null, void 0, 2];
351
- removeFromArray(nullishArr, null);
352
- expect(nullishArr).toEqual([1, void 0, 2]);
353
- const nullishArr2 = [1, null, void 0, 2];
354
- removeFromArray(nullishArr2, void 0);
355
- expect(nullishArr2).toEqual([1, null, 2]);
356
- });
357
- test("should handle NaN correctly", () => {
358
- const nanArr = [1, Number.NaN, 2, Number.NaN];
359
- removeFromArray(nanArr, Number.NaN);
360
- expect(nanArr).toEqual([1, 2, Number.NaN]);
361
- });
362
- test("should handle sparse arrays", () => {
363
- const sparseArr = [1, , 3, , 5];
364
- removeFromArray(sparseArr, void 0);
365
- expect(sparseArr).toHaveLength(5);
366
- expect(sparseArr).toEqual([1, , 3, , 5]);
367
- });
368
- test("should handle arrays with complex objects", () => {
369
- const complexArr = [
370
- { id: 1, nested: { value: "a" } },
371
- { id: 2, nested: { value: "b" } },
372
- { id: 1, nested: { value: "a" } }
373
- // Same content but different reference
374
- ];
375
- const targetObj = complexArr[0];
376
- removeFromArray(complexArr, targetObj);
377
- expect(complexArr).toHaveLength(2);
378
- expect(complexArr[0]).toEqual({ id: 2, nested: { value: "b" } });
379
- expect(complexArr[1]).toEqual({ id: 1, nested: { value: "a" } });
380
- removeFromArray(complexArr, { id: 1, nested: { value: "a" } });
381
- expect(complexArr).toHaveLength(2);
382
- });
383
- test("should handle arrays with different primitive types", () => {
384
- let mixedArr = [1, "1", true, /* @__PURE__ */ BigInt("1"), Symbol("test")];
385
- removeFromArray(mixedArr, 1);
386
- expect(mixedArr).toEqual(["1", true, /* @__PURE__ */ BigInt("1"), expect.any(Symbol)]);
387
- mixedArr = [1, "1", true, /* @__PURE__ */ BigInt("1"), Symbol("test")];
388
- removeFromArray(mixedArr, "1");
389
- expect(mixedArr).toEqual([1, true, /* @__PURE__ */ BigInt("1"), expect.any(Symbol)]);
390
- const mixedArray = [
391
- "string",
392
- 42,
393
- true,
394
- null,
395
- void 0,
396
- { obj: "value" },
397
- [1, 2, 3],
398
- Symbol("test"),
399
- () => "fn",
400
- /* @__PURE__ */ new Date(),
401
- /regex/,
402
- /* @__PURE__ */ new Map(),
403
- /* @__PURE__ */ new Set()
404
- ];
405
- const originalLength = mixedArray.length;
406
- removeFromArray(mixedArray, "nonexistent");
407
- expect(mixedArray).toHaveLength(originalLength);
408
- removeFromArray(mixedArray, 42);
409
- expect(mixedArray).toHaveLength(originalLength - 1);
410
- expect(mixedArray.includes(42)).toBe(false);
411
- });
412
- test("should preserve array structure", () => {
413
- const arr = [1, 2, 3];
414
- arr.customProperty = "test";
415
- removeFromArray(arr, 2);
416
- expect(arr.length).toBe(2);
417
- expect(arr[0]).toBe(1);
418
- expect(arr[1]).toBe(3);
419
- expect(arr).toHaveProperty("customProperty", "test");
420
- expect(arr.customProperty).toBe("test");
421
- });
422
- test("should handle array with getter/setter elements", () => {
423
- const arr = [1, 2, 3];
424
- Object.defineProperty(arr, "1", {
425
- get() {
426
- return "getter";
427
- },
428
- set() {
429
- },
430
- enumerable: true
431
- });
432
- removeFromArray(arr, "getter");
433
- expect(arr).toHaveLength(2);
434
- expect(arr[0]).toBe(1);
435
- expect(arr[1]).toBe("getter");
436
- });
437
- test("should handle strict equality in removeFromArray", () => {
438
- const obj1 = { id: 1 };
439
- const obj2 = { id: 1 };
440
- const arr = [obj1, obj2];
441
- removeFromArray(arr, obj1);
442
- expect(arr).toHaveLength(1);
443
- expect(arr[0]).toBe(obj2);
444
- removeFromArray(arr, { id: 1 });
445
- expect(arr).toHaveLength(1);
446
- });
447
- });
448
- describe("isValidConfirmHookResult", () => {
449
- test("should return true for boolean values", () => {
450
- expect(isValidConfirmHookResult(true)).toBe(false);
451
- expect(isValidConfirmHookResult(false)).toBe(true);
452
- expect(isValidConfirmHookResult(new Boolean(true))).toBe(false);
453
- expect(isValidConfirmHookResult(new Boolean(false))).toBe(false);
454
- });
455
- test("should return true for string values", () => {
456
- expect(isValidConfirmHookResult("")).toBe(true);
457
- expect(isValidConfirmHookResult("0")).toBe(true);
458
- expect(isValidConfirmHookResult("1")).toBe(true);
459
- expect(isValidConfirmHookResult("test")).toBe(true);
460
- expect(isValidConfirmHookResult(new String(""))).toBe(false);
461
- expect(isValidConfirmHookResult(new String("0"))).toBe(false);
462
- expect(isValidConfirmHookResult(new String("1"))).toBe(false);
463
- expect(isValidConfirmHookResult(new String("test"))).toBe(false);
464
- });
465
- test("should return true for function values", () => {
466
- expect(isValidConfirmHookResult(() => {
467
- })).toBe(true);
468
- expect(isValidConfirmHookResult(async () => {
469
- })).toBe(true);
470
- expect(isValidConfirmHookResult(new Function("return 1;"))).toBe(true);
471
- expect(isValidConfirmHookResult(AsyncFunction("return 1;"))).toBe(true);
472
- });
473
- test("should return true for plain objects", () => {
474
- expect(isValidConfirmHookResult({})).toBe(true);
475
- expect(isValidConfirmHookResult({ key: "value" })).toBe(true);
476
- expect(isValidConfirmHookResult(new Object())).toBe(true);
477
- expect(isValidConfirmHookResult(/* @__PURE__ */ Object.create(null))).toBe(true);
478
- expect(isValidConfirmHookResult(/* @__PURE__ */ Object.create({}))).toBe(true);
479
- expect(isValidConfirmHookResult(Object.create(Object.prototype))).toBe(
480
- true
481
- );
482
- expect(isValidConfirmHookResult({ __proto__: null })).toBe(true);
483
- expect(isValidConfirmHookResult({ [Symbol.toStringTag]: "Tag" })).toBe(
484
- true
485
- );
486
- expect(
487
- isValidConfirmHookResult({
488
- toString: () => "[object CustomObject]"
489
- })
490
- ).toBe(true);
491
- expect(isValidConfirmHookResult(Math)).toBe(true);
492
- expect(isValidConfirmHookResult(JSON)).toBe(true);
493
- });
494
- test("should return false for invalid types", () => {
495
- expect(isValidConfirmHookResult(null)).toBe(false);
496
- expect(isValidConfirmHookResult(void 0)).toBe(false);
497
- expect(isValidConfirmHookResult(123)).toBe(false);
498
- expect(isValidConfirmHookResult(0)).toBe(false);
499
- expect(isValidConfirmHookResult(/* @__PURE__ */ BigInt("123"))).toBe(false);
500
- expect(isValidConfirmHookResult(/* @__PURE__ */ BigInt("0"))).toBe(false);
501
- expect(isValidConfirmHookResult(new Number("1"))).toBe(false);
502
- expect(isValidConfirmHookResult(+"a")).toBe(false);
503
- expect(isValidConfirmHookResult(Number.NaN)).toBe(false);
504
- expect(isValidConfirmHookResult(new Number("a"))).toBe(false);
505
- expect(isValidConfirmHookResult([])).toBe(false);
506
- expect(isValidConfirmHookResult(["a", "b"])).toBe(false);
507
- expect(isValidConfirmHookResult(new Array())).toBe(false);
508
- expect(isValidConfirmHookResult(new Array(1, 2, 3))).toBe(false);
509
- expect(isValidConfirmHookResult(new Array(1))).toBe(false);
510
- expect(isValidConfirmHookResult(new Uint8Array(8))).toBe(false);
511
- expect(isValidConfirmHookResult(new ArrayBuffer(8))).toBe(false);
512
- expect(isValidConfirmHookResult(new DataView(new ArrayBuffer(8)))).toBe(
513
- false
514
- );
515
- expect(isValidConfirmHookResult(/* @__PURE__ */ new Date())).toBe(false);
516
- expect(isValidConfirmHookResult(Symbol("test"))).toBe(false);
517
- expect(isValidConfirmHookResult(/* @__PURE__ */ new Map())).toBe(false);
518
- expect(isValidConfirmHookResult(/* @__PURE__ */ new Set())).toBe(false);
519
- expect(isValidConfirmHookResult(/* @__PURE__ */ new WeakMap())).toBe(false);
520
- expect(isValidConfirmHookResult(/* @__PURE__ */ new WeakSet())).toBe(false);
521
- expect(isValidConfirmHookResult(/test/)).toBe(false);
522
- expect(isValidConfirmHookResult(new Error("test"))).toBe(false);
523
- expect(isValidConfirmHookResult(Promise.resolve())).toBe(false);
524
- expect(isValidConfirmHookResult(new URL("https://example.com"))).toBe(
525
- false
526
- );
527
- expect(isValidConfirmHookResult(new URLSearchParams("key=value"))).toBe(
528
- false
529
- );
530
- expect(isValidConfirmHookResult(new Blob(["test"]))).toBe(false);
531
- expect(isValidConfirmHookResult(new File(["test"], "file.txt"))).toBe(
532
- false
533
- );
534
- });
535
- test("should handle edge cases for confirmation hook results", () => {
536
- expect(isValidConfirmHookResult(Promise.resolve(true))).toBe(false);
537
- const rejectedPromise = Promise.reject(false);
538
- rejectedPromise.catch(() => {
539
- });
540
- expect(isValidConfirmHookResult(rejectedPromise)).toBe(false);
541
- const asyncFn = async () => true;
542
- expect(isValidConfirmHookResult(asyncFn)).toBe(true);
543
- expect(isValidConfirmHookResult((x) => x > 0)).toBe(true);
544
- expect(isValidConfirmHookResult((x) => x > 0)).toBe(true);
545
- expect(
546
- isValidConfirmHookResult(function* () {
547
- yield 1;
548
- })
549
- ).toBe(true);
550
- class TestClass {
551
- }
552
- expect(isValidConfirmHookResult(TestClass)).toBe(true);
553
- });
554
- test("should handle objects with Symbol properties", () => {
555
- const symKey = Symbol("key");
556
- const objWithSymbol = { [symKey]: "value", regular: "prop" };
557
- expect(isValidConfirmHookResult(objWithSymbol)).toBe(true);
558
- const objWithToStringTag = { [Symbol.toStringTag]: "CustomObject" };
559
- expect(isValidConfirmHookResult(objWithToStringTag)).toBe(true);
560
- });
561
- test("should handle frozen and sealed objects", () => {
562
- const frozenObj = Object.freeze({ frozen: true });
563
- expect(isValidConfirmHookResult(frozenObj)).toBe(true);
564
- const sealedObj = Object.seal({ sealed: true });
565
- expect(isValidConfirmHookResult(sealedObj)).toBe(true);
566
- const nonExtensibleObj = Object.preventExtensions({
567
- nonExtensible: true
568
- });
569
- expect(isValidConfirmHookResult(nonExtensibleObj)).toBe(true);
570
- });
571
- test("should handle function edge cases", () => {
572
- const originalFn = function(x) {
573
- return this.value + x;
574
- };
575
- const boundFn = originalFn.bind({ value: 10 });
576
- expect(isValidConfirmHookResult(boundFn)).toBe(true);
577
- expect(isValidConfirmHookResult(originalFn.call)).toBe(true);
578
- expect(isValidConfirmHookResult(originalFn.apply)).toBe(true);
579
- expect(isValidConfirmHookResult(console.log)).toBe(true);
580
- expect(isValidConfirmHookResult(Math.max)).toBe(true);
581
- expect(isValidConfirmHookResult(Array.prototype.push)).toBe(true);
582
- });
583
- test("should handle class and constructor edge cases", () => {
584
- class TestClass {
585
- constructor(value) {
586
- this.value = value;
587
- }
588
- }
589
- expect(isValidConfirmHookResult(new TestClass(42))).toBe(true);
590
- class ChildClass extends TestClass {
591
- }
592
- expect(isValidConfirmHookResult(new ChildClass(42))).toBe(true);
593
- expect(isValidConfirmHookResult(new Error("test"))).toBe(false);
594
- expect(isValidConfirmHookResult(new TypeError("test"))).toBe(false);
595
- });
596
- });
597
- describe("Performance Tests", () => {
598
- test("should handle large arrays efficiently in removeFromArray", () => {
599
- const largeArray = Array.from({ length: 1e4 }, (_, i) => i);
600
- const target = 5e3;
601
- const start = performance.now();
602
- removeFromArray(largeArray, target);
603
- const end = performance.now();
604
- expect(largeArray).toHaveLength(9999);
605
- expect(largeArray.includes(target)).toBe(false);
606
- expect(end - start).toBeLessThan(100);
607
- });
608
- test("should handle multiple rapid calls to utility functions", () => {
609
- const iterations = 1e3;
610
- const start = performance.now();
611
- for (let i = 0; i < iterations; ++i) {
612
- isNotNullish(i);
613
- isPlainObject({ value: i });
614
- isValidConfirmHookResult(false);
615
- }
616
- const end = performance.now();
617
- expect(end - start).toBeLessThan(50);
618
- });
619
- test("should handle rapid array modifications", () => {
620
- const arr = [1, 2, 3, 4, 5];
621
- const start = performance.now();
622
- removeFromArray(arr, 3);
623
- removeFromArray(arr, 1);
624
- removeFromArray(arr, 5);
625
- removeFromArray(arr, 99);
626
- const end = performance.now();
627
- expect(arr).toEqual([2, 4]);
628
- expect(end - start).toBeLessThan(10);
629
- });
630
- });
631
- describe("Error Handling Tests", () => {
632
- test("should handle circular references in objects", () => {
633
- const circularObj = { name: "circular" };
634
- circularObj.self = circularObj;
635
- expect(() => isPlainObject(circularObj)).not.toThrow();
636
- expect(() => isValidConfirmHookResult(circularObj)).not.toThrow();
637
- expect(() => isNotNullish(circularObj)).not.toThrow();
638
- expect(isPlainObject(circularObj)).toBe(true);
639
- expect(isValidConfirmHookResult(circularObj)).toBe(true);
640
- expect(isNotNullish(circularObj)).toBe(true);
641
- });
642
- });
643
- describe("isUrlEqual", () => {
644
- test("should return false when url2 is null or undefined", () => {
645
- const url1 = new URL("https://example.com/path");
646
- expect(isUrlEqual(url1, null)).toBe(false);
647
- expect(isUrlEqual(url1, void 0)).toBe(false);
648
- expect(isUrlEqual(url1)).toBe(false);
649
- const urlWithQuery = new URL("https://example.com/path?a=1&b=2");
650
- expect(isUrlEqual(urlWithQuery, null)).toBe(false);
651
- expect(isUrlEqual(urlWithQuery, void 0)).toBe(false);
652
- expect(isUrlEqual(urlWithQuery)).toBe(false);
653
- const urlWithHash = new URL("https://example.com/path#section");
654
- expect(isUrlEqual(urlWithHash, null)).toBe(false);
655
- expect(isUrlEqual(urlWithHash)).toBe(false);
656
- const urlWithUserInfo = new URL("https://user:pass@example.com/path");
657
- expect(isUrlEqual(urlWithUserInfo, null)).toBe(false);
658
- expect(isUrlEqual(urlWithUserInfo)).toBe(false);
659
- });
660
- test("should return true for identical URL objects", () => {
661
- const url1 = new URL("https://example.com/path?a=1&b=2");
662
- const url2 = new URL("https://example.com/path?a=1&b=2");
663
- expect(isUrlEqual(url1, url2)).toBe(true);
664
- });
665
- test("should return true for same reference", () => {
666
- const url = new URL("https://example.com/path");
667
- expect(isUrlEqual(url, url)).toBe(true);
668
- });
669
- test("should return false for different protocols", () => {
670
- const url1 = new URL("http://example.com/path");
671
- const url2 = new URL("https://example.com/path");
672
- expect(isUrlEqual(url1, url2)).toBe(false);
673
- });
674
- test("should return false for different hostnames", () => {
675
- const url1 = new URL("https://example.com/path");
676
- const url2 = new URL("https://test.com/path");
677
- expect(isUrlEqual(url1, url2)).toBe(false);
678
- });
679
- test("should return false for different ports", () => {
680
- const url1 = new URL("https://example.com:8080/path");
681
- const url2 = new URL("https://example.com:9090/path");
682
- expect(isUrlEqual(url1, url2)).toBe(false);
683
- });
684
- test("should return false for different pathnames", () => {
685
- const url1 = new URL("https://example.com/path1");
686
- const url2 = new URL("https://example.com/path2");
687
- expect(isUrlEqual(url1, url2)).toBe(false);
688
- });
689
- test("should return false for different hashes", () => {
690
- const url1 = new URL("https://example.com/path#section1");
691
- const url2 = new URL("https://example.com/path#section2");
692
- expect(isUrlEqual(url1, url2)).toBe(false);
693
- });
694
- test("should handle empty hashes correctly", () => {
695
- const url1 = new URL("https://example.com/path");
696
- const url2 = new URL("https://example.com/path#");
697
- expect(isUrlEqual(url1, url2)).toBe(true);
698
- });
699
- test("should ignore query parameter order", () => {
700
- const url1 = new URL("https://example.com/path?a=1&b=2&c=3");
701
- const url2 = new URL("https://example.com/path?c=3&a=1&b=2");
702
- expect(isUrlEqual(url1, url2)).toBe(true);
703
- });
704
- test("should handle duplicate query parameters correctly", () => {
705
- const url1 = new URL("https://example.com/path?a=1&a=2&b=3");
706
- const url2 = new URL("https://example.com/path?b=3&a=2&a=1");
707
- expect(isUrlEqual(url1, url2)).toBe(false);
708
- });
709
- test("should return false for different duplicate parameter values", () => {
710
- const url1 = new URL("https://example.com/path?a=1&a=2");
711
- const url2 = new URL("https://example.com/path?a=1&a=3");
712
- expect(isUrlEqual(url1, url2)).toBe(false);
713
- });
714
- test("should return false for different number of duplicate parameters", () => {
715
- const url1 = new URL("https://example.com/path?a=1&a=2");
716
- const url2 = new URL("https://example.com/path?a=1");
717
- expect(isUrlEqual(url1, url2)).toBe(false);
718
- });
719
- test("should handle complex query parameter scenarios", () => {
720
- const url1 = new URL(
721
- "https://example.com/path?tag=red&tag=blue&category=tech&tag=green"
722
- );
723
- const url2 = new URL(
724
- "https://example.com/path?category=tech&tag=blue&tag=green&tag=red"
725
- );
726
- expect(isUrlEqual(url1, url2)).toBe(false);
727
- const url3 = new URL(
728
- "https://example.com/path?search=hello%20world&filter=a%26b"
729
- );
730
- const url4 = new URL(
731
- "https://example.com/path?filter=a%26b&search=hello%20world"
732
- );
733
- expect(isUrlEqual(url3, url4)).toBe(true);
734
- });
735
- test("should handle empty query parameters", () => {
736
- const url1 = new URL("https://example.com/path?");
737
- const url2 = new URL("https://example.com/path");
738
- expect(isUrlEqual(url1, url2)).toBe(true);
739
- const url3 = new URL("https://example.com/path?a=");
740
- const url4 = new URL("https://example.com/path?a=");
741
- expect(isUrlEqual(url3, url4)).toBe(true);
742
- });
743
- test("should handle URLs with userinfo", () => {
744
- const url1 = new URL("https://user:pass@example.com/path");
745
- const url2 = new URL("https://user:pass@example.com/path");
746
- expect(isUrlEqual(url1, url2)).toBe(true);
747
- const url3 = new URL("https://user1:pass@example.com/path");
748
- const url4 = new URL("https://user2:pass@example.com/path");
749
- expect(isUrlEqual(url3, url4)).toBe(false);
750
- });
751
- test("should handle default ports correctly", () => {
752
- const url1 = new URL("https://example.com/path");
753
- const url2 = new URL("https://example.com:443/path");
754
- expect(isUrlEqual(url1, url2)).toBe(true);
755
- const url3 = new URL("http://example.com/path");
756
- const url4 = new URL("http://example.com:80/path");
757
- expect(isUrlEqual(url3, url4)).toBe(true);
758
- });
759
- test("should handle trailing slashes in pathnames", () => {
760
- const url1 = new URL("https://example.com/path/");
761
- const url2 = new URL("https://example.com/path");
762
- expect(isUrlEqual(url1, url2)).toBe(false);
763
- });
764
- test("should handle case sensitivity correctly", () => {
765
- const url1 = new URL("https://Example.Com/path");
766
- const url2 = new URL("https://example.com/path");
767
- expect(isUrlEqual(url1, url2)).toBe(true);
768
- const url3 = new URL("https://example.com/Path");
769
- const url4 = new URL("https://example.com/path");
770
- expect(isUrlEqual(url3, url4)).toBe(false);
771
- const url5 = new URL("https://example.com/path?Key=Value");
772
- const url6 = new URL("https://example.com/path?key=value");
773
- expect(isUrlEqual(url5, url6)).toBe(false);
774
- });
775
- test("should handle special characters in URLs", () => {
776
- const url1 = new URL(
777
- "https://example.com/path with spaces?q=hello world"
778
- );
779
- const url2 = new URL(
780
- "https://example.com/path%20with%20spaces?q=hello%20world"
781
- );
782
- expect(isUrlEqual(url1, url2)).toBe(true);
783
- const url3 = new URL("https://example.com/path?unicode=\u6D4B\u8BD5");
784
- const url4 = new URL(
785
- "https://example.com/path?unicode=%E6%B5%8B%E8%AF%95"
786
- );
787
- expect(isUrlEqual(url3, url4)).toBe(true);
788
- });
789
- test("should handle edge cases with empty values", () => {
790
- const url1 = new URL("https://example.com/path?a=&b=test");
791
- const url2 = new URL("https://example.com/path?b=test&a=");
792
- expect(isUrlEqual(url1, url2)).toBe(true);
793
- const url3 = new URL("https://example.com/path?flag");
794
- const url4 = new URL("https://example.com/path?flag=");
795
- expect(isUrlEqual(url3, url4)).toBe(true);
796
- });
797
- test("should handle performance with many parameters", () => {
798
- const params1 = new URLSearchParams();
799
- const params2 = new URLSearchParams();
800
- for (let i = 0; i < 100; i++) {
801
- params1.append("param".concat(i), "value".concat(i));
802
- params2.append("param".concat(99 - i), "value".concat(99 - i));
803
- }
804
- const url1 = new URL("https://example.com/path?".concat(params1));
805
- const url2 = new URL("https://example.com/path?".concat(params2));
806
- const start = performance.now();
807
- const result = isUrlEqual(url1, url2);
808
- const end = performance.now();
809
- expect(result).toBe(true);
810
- expect(end - start).toBeLessThan(50);
811
- });
812
- test("should handle complex real-world scenarios", () => {
813
- const baseUrl = "https://api.example.com/v1/users";
814
- const url1 = new URL(
815
- "".concat(baseUrl, "?page=1&limit=20&sort=name&filter=active&tag=user&tag=admin")
816
- );
817
- const url2 = new URL(
818
- "".concat(baseUrl, "?limit=20&tag=user&page=1&tag=admin&filter=active&sort=name")
819
- );
820
- expect(isUrlEqual(url1, url2)).toBe(true);
821
- const oauthUrl1 = new URL(
822
- "https://oauth.example.com/authorize?client_id=123&redirect_uri=https%3A%2F%2Fapp.com%2Fcallback&scope=read%20write&state=random123"
823
- );
824
- const oauthUrl2 = new URL(
825
- "https://oauth.example.com/authorize?scope=read%20write&state=random123&client_id=123&redirect_uri=https%3A%2F%2Fapp.com%2Fcallback"
826
- );
827
- expect(isUrlEqual(oauthUrl1, oauthUrl2)).toBe(true);
828
- });
829
- });
830
- describe("isRouteMatched", () => {
831
- const createOptions = () => {
832
- return parsedOptions({
833
- base: new URL("http://localhost:3000/"),
834
- routes: [
835
- { path: "/user/:id", component: "UserComponent" },
836
- { path: "/settings", component: "SettingsComponent" }
837
- ]
838
- });
839
- };
840
- describe("route match type", () => {
841
- test("should match routes with same config", () => {
842
- const options = createOptions();
843
- const route1 = new Route({
844
- options,
845
- toType: RouteType.push,
846
- toInput: "/user/123"
847
- });
848
- const route2 = new Route({
849
- options,
850
- toType: RouteType.push,
851
- toInput: "/user/456"
852
- });
853
- expect(isRouteMatched(route1, route2, "route")).toBe(true);
854
- });
855
- test("should not match routes with different config", () => {
856
- const options = createOptions();
857
- const route1 = new Route({
858
- options,
859
- toType: RouteType.push,
860
- toInput: "/user/123"
861
- });
862
- const route2 = new Route({
863
- options,
864
- toType: RouteType.push,
865
- toInput: "/settings"
866
- });
867
- expect(isRouteMatched(route1, route2, "route")).toBe(false);
868
- });
869
- test("should return false when second route is null", () => {
870
- const options = createOptions();
871
- const route1 = new Route({
872
- options,
873
- toType: RouteType.push,
874
- toInput: "/user/123"
875
- });
876
- expect(isRouteMatched(route1, null, "route")).toBe(false);
877
- });
878
- });
879
- describe("exact match type", () => {
880
- test("should match routes with same fullPath", () => {
881
- const options = createOptions();
882
- const route1 = new Route({
883
- options,
884
- toType: RouteType.push,
885
- toInput: "/user/123?tab=profile"
886
- });
887
- const route2 = new Route({
888
- options,
889
- toType: RouteType.push,
890
- toInput: "/user/123?tab=profile"
891
- });
892
- expect(isRouteMatched(route1, route2, "exact")).toBe(true);
893
- });
894
- test("should not match routes with different fullPath", () => {
895
- const options = createOptions();
896
- const route1 = new Route({
897
- options,
898
- toType: RouteType.push,
899
- toInput: "/user/123?tab=profile"
900
- });
901
- const route2 = new Route({
902
- options,
903
- toType: RouteType.push,
904
- toInput: "/user/123?tab=settings"
905
- });
906
- expect(isRouteMatched(route1, route2, "exact")).toBe(false);
907
- });
908
- test("should not match routes with same path but different query", () => {
909
- const options = createOptions();
910
- const route1 = new Route({
911
- options,
912
- toType: RouteType.push,
913
- toInput: "/user/123"
914
- });
915
- const route2 = new Route({
916
- options,
917
- toType: RouteType.push,
918
- toInput: "/user/123?tab=profile"
919
- });
920
- expect(isRouteMatched(route1, route2, "exact")).toBe(false);
921
- });
922
- });
923
- describe("include match type", () => {
924
- test("should match when route1 fullPath starts with route2 fullPath", () => {
925
- const options = createOptions();
926
- const route1 = new Route({
927
- options,
928
- toType: RouteType.push,
929
- toInput: "/user/123/profile/settings"
930
- });
931
- const route2 = new Route({
932
- options,
933
- toType: RouteType.push,
934
- toInput: "/user/123"
935
- });
936
- expect(isRouteMatched(route1, route2, "include")).toBe(true);
937
- });
938
- test("should match when fullPaths are exactly the same", () => {
939
- const options = createOptions();
940
- const route1 = new Route({
941
- options,
942
- toType: RouteType.push,
943
- toInput: "/user/123"
944
- });
945
- const route2 = new Route({
946
- options,
947
- toType: RouteType.push,
948
- toInput: "/user/123"
949
- });
950
- expect(isRouteMatched(route1, route2, "include")).toBe(true);
951
- });
952
- test("should not match when route1 fullPath does not start with route2 fullPath", () => {
953
- const options = createOptions();
954
- const route1 = new Route({
955
- options,
956
- toType: RouteType.push,
957
- toInput: "/user/123"
958
- });
959
- const route2 = new Route({
960
- options,
961
- toType: RouteType.push,
962
- toInput: "/user/456"
963
- });
964
- expect(isRouteMatched(route1, route2, "include")).toBe(false);
965
- });
966
- test("should not match when route2 fullPath is longer", () => {
967
- const options = createOptions();
968
- const route1 = new Route({
969
- options,
970
- toType: RouteType.push,
971
- toInput: "/user"
972
- });
973
- const route2 = new Route({
974
- options,
975
- toType: RouteType.push,
976
- toInput: "/user/123"
977
- });
978
- expect(isRouteMatched(route1, route2, "include")).toBe(false);
979
- });
980
- });
981
- describe("edge cases", () => {
982
- test("should handle root path correctly", () => {
983
- const options = createOptions();
984
- const route1 = new Route({ options });
985
- const route2 = new Route({ options });
986
- expect(isRouteMatched(route1, route2, "route")).toBe(true);
987
- expect(isRouteMatched(route1, route2, "exact")).toBe(true);
988
- expect(isRouteMatched(route1, route2, "include")).toBe(true);
989
- });
990
- test("should handle hash in fullPath", () => {
991
- const options = createOptions();
992
- const route1 = new Route({
993
- options,
994
- toType: RouteType.push,
995
- toInput: "/user/123#section1"
996
- });
997
- const route2 = new Route({
998
- options,
999
- toType: RouteType.push,
1000
- toInput: "/user/123#section2"
1001
- });
1002
- expect(isRouteMatched(route1, route2, "route")).toBe(true);
1003
- expect(isRouteMatched(route1, route2, "exact")).toBe(false);
1004
- });
1005
- test("should return false for invalid match type", () => {
1006
- const options = createOptions();
1007
- const route1 = new Route({
1008
- options,
1009
- toType: RouteType.push,
1010
- toInput: "/user/123"
1011
- });
1012
- const route2 = new Route({
1013
- options,
1014
- toType: RouteType.push,
1015
- toInput: "/user/123"
1016
- });
1017
- expect(isRouteMatched(route1, route2, "invalid")).toBe(false);
1018
- });
1019
- });
1020
- });