@@ -19,22 +19,10 @@ ko.components.register('test', {
19
19
t . end ( )
20
20
} )
21
21
22
- test ( 'implicit initialization' , ( t ) => {
23
- history . replaceState ( null , null , location . pathname + '?{"foo": "foo"}' )
24
-
25
- const query = new Query ( )
26
-
27
- t . ok ( ko . isWritableObservable ( query . foo ) , 'can be created on-the-fly' )
28
- t . equals ( 'foo' , query . foo ( ) , 'implicit params are initialized from query string' )
29
-
30
- query . dispose ( )
31
- t . end ( )
32
- } )
33
-
34
22
test ( 'url parsing' , ( t ) => {
35
23
history . replaceState ( null , null , location . pathname + '#hash' )
36
24
37
- const query = new Query ( )
25
+ const query = new Query ( { foo : undefined } )
38
26
39
27
query . foo ( 'foo' )
40
28
ko . tasks . runEarly ( )
@@ -48,7 +36,7 @@ ko.components.register('test', {
48
36
test ( 'empty query' , ( t ) => {
49
37
history . replaceState ( null , null , location . pathname )
50
38
51
- const query = new Query ( )
39
+ const query = new Query ( { foo : undefined } )
52
40
53
41
query . foo ( 'foo' )
54
42
query . foo ( undefined )
@@ -183,7 +171,7 @@ ko.components.register('test', {
183
171
test ( '#toJS' , ( t ) => {
184
172
history . replaceState ( null , null , location . pathname + '?{"foo": "foo"}' )
185
173
186
- const query = new Query ( )
174
+ const query = new Query ( { foo : undefined } )
187
175
188
176
t . deepEquals ( { foo : 'foo' } , query . toJS ( ) , 'returns unwrapped query object' )
189
177
@@ -211,7 +199,7 @@ ko.components.register('test', {
211
199
212
200
history . replaceState ( null , null , location . pathname )
213
201
214
- const query = new Query ( )
202
+ const query = new Query ( { foo : undefined } )
215
203
const q = query . asObservable ( )
216
204
217
205
const killMe = q . subscribe ( ( ) => {
@@ -250,8 +238,8 @@ ko.components.register('test', {
250
238
test ( '#dispose' , ( t ) => {
251
239
history . replaceState ( null , null , location . pathname )
252
240
253
- const a1 = new Query ( { } , 'a' )
254
- const a2 = new Query ( { } , 'a' )
241
+ const a1 = new Query ( { foo : undefined } , 'a' )
242
+ const a2 = new Query ( { foo : undefined } , 'a' )
255
243
256
244
a1 . foo ( 'foo' )
257
245
ko . tasks . runEarly ( )
@@ -261,13 +249,6 @@ ko.components.register('test', {
261
249
262
250
t . deepEquals ( { a : { foo : 'foo' } } , Query . parse ( location . search . substring ( 1 ) ) , 'does not remove query if linked group remains' )
263
251
264
- try {
265
- a1 . foo ( 'notfoo' )
266
- t . fail ( 'does not dispose' )
267
- } catch ( e ) {
268
- t . pass ( 'disposes query' )
269
- }
270
-
271
252
a2 . dispose ( )
272
253
ko . tasks . runEarly ( )
273
254
@@ -277,8 +258,8 @@ ko.components.register('test', {
277
258
} )
278
259
279
260
test ( 'grouped/multiple queries' , ( t ) => {
280
- const a = new Query ( { } , 'a' )
281
- const b = new Query ( { } , 'b' )
261
+ const a = new Query ( { foo : undefined } , 'a' )
262
+ const b = new Query ( { foo : undefined } , 'b' )
282
263
283
264
a . foo ( 'foo' )
284
265
b . foo ( 'notfoo' )
@@ -294,20 +275,21 @@ ko.components.register('test', {
294
275
} )
295
276
296
277
test ( 'linked queries' , ( t ) => {
297
- const a1 = new Query ( { } , 'a' )
298
- a1 . foo ( ' foo')
278
+ const a1 = new Query ( { foo : undefined , bar : undefined } , 'a' )
279
+ const a2 = new Query ( { foo : undefined , bar : 'bar' , baz : undefined } , 'a ')
299
280
300
- const a2 = new Query ( { bar : 'bar' } , 'a ')
281
+ a1 . foo ( 'foo ')
301
282
302
283
ko . tasks . runEarly ( )
303
284
304
- t . equals ( 'foo' , a2 . foo ( ) , 'links via setter' )
305
- t . equals ( 'bar' , a1 . bar ( ) , 'links via defaults' )
285
+ t . equals ( 'foo' , a2 . foo ( ) , 'links' )
306
286
307
287
a1 . dispose ( )
308
288
309
- const a3 = new Query ( { baz : 'baz' } , 'a' )
289
+ const a3 = new Query ( { baz : undefined } , 'a' )
310
290
291
+ a3 . baz ( 'baz' )
292
+
311
293
ko . tasks . runEarly ( )
312
294
313
295
t . equals ( 'baz' , a2 . baz ( ) , 'works after a linked query is disposed' )
@@ -325,7 +307,7 @@ ko.components.register('test', {
325
307
stringify : ( obj ) => 'foo=' + obj . foo
326
308
} )
327
309
328
- const q = new Query ( )
310
+ const q = new Query ( { foo : undefined } )
329
311
330
312
t . equals ( q . foo ( ) , 'foo' , 'uses custom parse function' )
331
313
0 commit comments