@@ -3,31 +3,35 @@ import { createRouterContext } from "../src/routing.js";
3
3
import type { LocationChange } from "../src/types.js" ;
4
4
import { createAsyncRoot , createCounter , waitFor } from "./helpers.js" ;
5
5
6
- const fakeBranches = ( ) => [ ]
7
- const fakeContext = ( ) => ( { } )
6
+ const fakeBranches = ( ) => [ ] ;
7
+ const fakeContext = ( ) => ( { } ) ;
8
8
9
9
describe ( "Router should" , ( ) => {
10
10
describe ( "have member `base` which should" , ( ) => {
11
11
test ( `have a default path when base path is not defined` , ( ) => {
12
12
createRoot ( ( ) => {
13
13
const signal = createSignal < LocationChange > ( { value : "" } ) ;
14
- const { base } = createRouterContext ( { signal } ) ;
14
+ const { base } = createRouterContext ( { signal } , fakeBranches ) ;
15
15
expect ( base . path ( ) ) . toBe ( "/" ) ;
16
16
} ) ;
17
17
} ) ;
18
18
19
19
test ( `have a normalized version of the base path when defined` , ( ) => {
20
20
createRoot ( ( ) => {
21
21
const signal = createSignal < LocationChange > ( { value : "" } ) ;
22
- const { base } = createRouterContext ( { signal } , fakeContext , fakeBranches , { base : "base" } ) ;
22
+ const { base } = createRouterContext ( { signal } , fakeBranches , fakeContext , {
23
+ base : "base"
24
+ } ) ;
23
25
expect ( base . path ( ) ) . toBe ( "/base" ) ;
24
26
} ) ;
25
27
} ) ;
26
28
27
29
test ( `throw when the base path is invalid` , ( ) => {
28
30
createRoot ( ( ) => {
29
31
const signal = createSignal < LocationChange > ( { value : "" } ) ;
30
- expect ( ( ) => createRouterContext ( { signal } , fakeContext , fakeBranches , { base : "http://example.com" } ) ) . toThrow ( ) ;
32
+ expect ( ( ) =>
33
+ createRouterContext ( { signal } , fakeBranches , fakeContext , { base : "http://example.com" } )
34
+ ) . toThrow ( ) ;
31
35
} ) ;
32
36
} ) ;
33
37
} ) ;
@@ -38,7 +42,7 @@ describe("Router should", () => {
38
42
const signal = createSignal < LocationChange > ( {
39
43
value : "/foo/bar?hello=world"
40
44
} ) ;
41
- const { location } = createRouterContext ( { signal } ) ;
45
+ const { location } = createRouterContext ( { signal } , fakeBranches ) ;
42
46
expect ( location . pathname ) . toBe ( "/foo/bar" ) ;
43
47
expect ( location . search ) . toBe ( "?hello=world" ) ;
44
48
} ) ;
@@ -51,7 +55,7 @@ describe("Router should", () => {
51
55
const signal = createSignal < LocationChange > ( {
52
56
value : "/foo/bar?hello=world"
53
57
} ) ;
54
- const { location } = createRouterContext ( { signal } ) ;
58
+ const { location } = createRouterContext ( { signal } , fakeBranches ) ;
55
59
expect ( location . pathname ) . toBe ( "/foo/bar" ) ;
56
60
signal [ 1 ] ( { value : expected + "?hello=world" } ) ;
57
61
waitFor ( ( ) => signal [ 0 ] ( ) . value === expected + "?hello=world" ) . then ( ( ) => {
@@ -65,7 +69,7 @@ describe("Router should", () => {
65
69
const signal = createSignal < LocationChange > ( {
66
70
value : "/foo/bar?hello=world"
67
71
} ) ;
68
- const { location } = createRouterContext ( { signal } ) ;
72
+ const { location } = createRouterContext ( { signal } , fakeBranches ) ;
69
73
const count = createCounter ( ( ) => location . pathname ) ;
70
74
expect ( location . pathname ) . toBe ( "/foo/bar" ) ;
71
75
signal [ 1 ] ( { value : "/foo/bar?fizz=buzz" } ) ;
@@ -78,7 +82,7 @@ describe("Router should", () => {
78
82
const signal = createSignal < LocationChange > ( {
79
83
value : "/foo bar+baz"
80
84
} ) ;
81
- const { location } = createRouterContext ( { signal } ) ;
85
+ const { location } = createRouterContext ( { signal } , fakeBranches ) ;
82
86
expect ( location . pathname ) . toBe ( "/foo%20bar+baz" ) ;
83
87
} ) ) ;
84
88
} ) ; // end of "contain property 'pathname'"
@@ -90,7 +94,7 @@ describe("Router should", () => {
90
94
const signal = createSignal < LocationChange > ( {
91
95
value : "/foo/bar?hello=world"
92
96
} ) ;
93
- const { location } = createRouterContext ( { signal } ) ;
97
+ const { location } = createRouterContext ( { signal } , fakeBranches ) ;
94
98
95
99
expect ( location . search ) . toBe ( "?hello=world" ) ;
96
100
signal [ 1 ] ( { value : "/foo/baz" + expected } ) ;
@@ -106,7 +110,7 @@ describe("Router should", () => {
106
110
const signal = createSignal < LocationChange > ( {
107
111
value : "/foo/bar?hello=world"
108
112
} ) ;
109
- const { location } = createRouterContext ( { signal } ) ;
113
+ const { location } = createRouterContext ( { signal } , fakeBranches ) ;
110
114
const count = createCounter ( ( ) => location . search ) ;
111
115
112
116
expect ( location . search ) . toBe ( "?hello=world" ) ;
@@ -120,7 +124,7 @@ describe("Router should", () => {
120
124
const signal = createSignal < LocationChange > ( {
121
125
value : "/foo?hello+world=bar+baz"
122
126
} ) ;
123
- const { location } = createRouterContext ( { signal } ) ;
127
+ const { location } = createRouterContext ( { signal } , fakeBranches ) ;
124
128
expect ( location . search ) . toBe ( "?hello+world=bar+baz" ) ;
125
129
} ) ) ;
126
130
} ) ; //end of "contain property 'search'"
@@ -131,7 +135,7 @@ describe("Router should", () => {
131
135
const signal = createSignal < LocationChange > ( {
132
136
value : "/foo#bar baz"
133
137
} ) ;
134
- const { location } = createRouterContext ( { signal } ) ;
138
+ const { location } = createRouterContext ( { signal } , fakeBranches ) ;
135
139
expect ( location . hash ) . toBe ( "#bar%20baz" ) ;
136
140
} ) ) ;
137
141
} ) ; // end of "contain property 'hash'"
@@ -142,7 +146,7 @@ describe("Router should", () => {
142
146
const signal = createSignal < LocationChange > ( {
143
147
value : "/foo/bar?hello=world&fizz=buzz"
144
148
} ) ;
145
- const { location } = createRouterContext ( { signal } ) ;
149
+ const { location } = createRouterContext ( { signal } , fakeBranches ) ;
146
150
expect ( location . query . hello ) . toEqual ( "world" ) ;
147
151
expect ( location . query . fizz ) . toEqual ( "buzz" ) ;
148
152
} ) ;
@@ -153,7 +157,7 @@ describe("Router should", () => {
153
157
const signal = createSignal < LocationChange > ( {
154
158
value : "/foo/bar?hello=world"
155
159
} ) ;
156
- const { location } = createRouterContext ( { signal } ) ;
160
+ const { location } = createRouterContext ( { signal } , fakeBranches ) ;
157
161
158
162
expect ( location . query . hello ) . toEqual ( "world" ) ;
159
163
signal [ 1 ] ( { value : "/foo/bar?hello=world&fizz=buzz" } ) ;
@@ -169,7 +173,7 @@ describe("Router should", () => {
169
173
const signal = createSignal < LocationChange > ( {
170
174
value : "/foo/bar?hello=world"
171
175
} ) ;
172
- const { location } = createRouterContext ( { signal } ) ;
176
+ const { location } = createRouterContext ( { signal } , fakeBranches ) ;
173
177
const count = createCounter ( ( ) => location . query . hello ) ;
174
178
175
179
expect ( location . query . hello ) . toEqual ( "world" ) ;
@@ -189,7 +193,7 @@ describe("Router should", () => {
189
193
const signal = createSignal < LocationChange > ( {
190
194
value : "/foo/bar?hello=world"
191
195
} ) ;
192
- const { location } = createRouterContext ( { signal } ) ;
196
+ const { location } = createRouterContext ( { signal } , fakeBranches ) ;
193
197
const count = createCounter ( ( ) => location . query . hello ) ;
194
198
195
199
expect ( location . query . hello ) . toEqual ( "world" ) ;
@@ -211,7 +215,7 @@ describe("Router should", () => {
211
215
const signal = createSignal < LocationChange > ( {
212
216
value : "/"
213
217
} ) ;
214
- const { location, navigatorFactory } = createRouterContext ( { signal } ) ;
218
+ const { location, navigatorFactory } = createRouterContext ( { signal } , fakeBranches ) ;
215
219
const navigate = navigatorFactory ( ) ;
216
220
217
221
expect ( location . pathname ) . toBe ( "/" ) ;
@@ -228,7 +232,7 @@ describe("Router should", () => {
228
232
const signal = createSignal < LocationChange > ( {
229
233
value : "/foo/bar"
230
234
} ) ;
231
- const { location, navigatorFactory } = createRouterContext ( { signal } ) ;
235
+ const { location, navigatorFactory } = createRouterContext ( { signal } , fakeBranches ) ;
232
236
const navigate = navigatorFactory ( ) ;
233
237
const count = createCounter ( ( ) => location . pathname ) ;
234
238
@@ -246,7 +250,7 @@ describe("Router should", () => {
246
250
const signal = createSignal < LocationChange > ( {
247
251
value : "/"
248
252
} ) ;
249
- const { navigatorFactory } = createRouterContext ( { signal } ) ;
253
+ const { navigatorFactory } = createRouterContext ( { signal } , fakeBranches ) ;
250
254
const navigate = navigatorFactory ( ) ;
251
255
expect ( signal [ 0 ] ( ) . value ) . toBe ( "/" ) ;
252
256
navigate ( "/foo/bar" ) ;
@@ -263,7 +267,7 @@ describe("Router should", () => {
263
267
const state = { foo : "bar" } ;
264
268
const signal = createSignal < LocationChange > ( { value : "/" } ) ;
265
269
266
- const { location, navigatorFactory } = createRouterContext ( { signal } ) ;
270
+ const { location, navigatorFactory } = createRouterContext ( { signal } , fakeBranches ) ;
267
271
const navigate = navigatorFactory ( ) ;
268
272
269
273
expect ( location . state ) . toBeUndefined ( ) ;
@@ -281,7 +285,7 @@ describe("Router should", () => {
281
285
const state = { foo : "bar" } ;
282
286
const signal = createSignal < LocationChange > ( { value : "/" } ) ;
283
287
284
- const { location, navigatorFactory } = createRouterContext ( { signal } ) ;
288
+ const { location, navigatorFactory } = createRouterContext ( { signal } , fakeBranches ) ;
285
289
const navigate = navigatorFactory ( ) ;
286
290
287
291
expect ( location . state ) . toBeUndefined ( ) ;
@@ -299,7 +303,7 @@ describe("Router should", () => {
299
303
const signal = createSignal < LocationChange > ( {
300
304
value : "/"
301
305
} ) ;
302
- const { navigatorFactory } = createRouterContext ( { signal } ) ;
306
+ const { navigatorFactory } = createRouterContext ( { signal } , fakeBranches ) ;
303
307
const navigate = navigatorFactory ( ) ;
304
308
305
309
expect ( signal [ 0 ] ( ) ) . toEqual ( { value : "/" } ) ;
@@ -321,7 +325,7 @@ describe("Router should", () => {
321
325
const signal = createSignal < LocationChange > ( {
322
326
value : "/"
323
327
} ) ;
324
- const { navigatorFactory } = createRouterContext ( { signal } ) ;
328
+ const { navigatorFactory } = createRouterContext ( { signal } , fakeBranches ) ;
325
329
const navigate = navigatorFactory ( ) ;
326
330
function pushAlot ( ) {
327
331
for ( let i = 0 ; i < 101 ; i ++ ) {
0 commit comments