@@ -292,22 +292,24 @@ describe('Observer', function () {
292
292
293
293
describe ( 'Augmentations' , function ( ) {
294
294
295
- it ( '$remove (index) ' , function ( ) {
295
+ it ( '$set ' , function ( ) {
296
296
var emitted = false ,
297
297
index = ~ ~ ( Math . random ( ) * arr . length ) ,
298
- expected = arr [ index ] = { a : 1 }
298
+ expected = arr [ index ] = { a : 1 } ,
299
+ arg = 34567
299
300
ob . once ( 'mutate' , function ( key , array , mutation ) {
300
301
emitted = true
301
302
assert . strictEqual ( mutation . method , 'splice' )
302
- assert . strictEqual ( mutation . args . length , 2 )
303
+ assert . strictEqual ( mutation . args . length , 3 )
303
304
assert . strictEqual ( mutation . args [ 0 ] , index )
304
305
} )
305
- var r = arr . $remove ( index )
306
+ var r = arr . $set ( index , arg )
306
307
assert . ok ( emitted )
307
308
assert . strictEqual ( r , expected )
309
+ assert . strictEqual ( arr [ index ] , arg )
308
310
} )
309
-
310
- it ( '$remove (object )' , function ( ) {
311
+
312
+ it ( '$remove (index )' , function ( ) {
311
313
var emitted = false ,
312
314
index = ~ ~ ( Math . random ( ) * arr . length ) ,
313
315
expected = arr [ index ] = { a : 1 }
@@ -317,70 +319,24 @@ describe('Observer', function () {
317
319
assert . strictEqual ( mutation . args . length , 2 )
318
320
assert . strictEqual ( mutation . args [ 0 ] , index )
319
321
} )
320
- var r = arr . $remove ( expected )
321
- assert . ok ( emitted )
322
- assert . strictEqual ( r , expected )
323
- } )
324
-
325
- it ( '$remove (function)' , function ( ) {
326
- var expected = [ 1001 , 1002 ]
327
- arr . push . apply ( arr , expected )
328
- var filter = function ( e ) {
329
- return e > 1000
330
- } ,
331
- copy = arr . filter ( function ( e ) {
332
- return e <= 1000
333
- } )
334
- var removed = arr . $remove ( filter )
335
- assert . deepEqual ( arr , copy )
336
- assert . deepEqual ( expected , removed )
337
- } )
338
-
339
- it ( '$replace (index)' , function ( ) {
340
- var emitted = false ,
341
- index = ~ ~ ( Math . random ( ) * arr . length ) ,
342
- expected = arr [ index ] = { a : 1 } ,
343
- arg = 34567
344
- ob . once ( 'mutate' , function ( key , array , mutation ) {
345
- emitted = true
346
- assert . strictEqual ( mutation . method , 'splice' )
347
- assert . strictEqual ( mutation . args . length , 3 )
348
- assert . strictEqual ( mutation . args [ 0 ] , index )
349
- } )
350
- var r = arr . $replace ( index , arg )
322
+ var r = arr . $remove ( index )
351
323
assert . ok ( emitted )
352
324
assert . strictEqual ( r , expected )
353
- assert . strictEqual ( arr [ index ] , arg )
354
325
} )
355
-
356
- it ( '$replace (object)' , function ( ) {
326
+
327
+ it ( '$remove (object)' , function ( ) {
357
328
var emitted = false ,
358
329
index = ~ ~ ( Math . random ( ) * arr . length ) ,
359
- expected = arr [ index ] = { a : 1 } ,
360
- arg = 45678
330
+ expected = arr [ index ] = { a : 1 }
361
331
ob . once ( 'mutate' , function ( key , array , mutation ) {
362
332
emitted = true
363
333
assert . strictEqual ( mutation . method , 'splice' )
364
- assert . strictEqual ( mutation . args . length , 3 )
334
+ assert . strictEqual ( mutation . args . length , 2 )
365
335
assert . strictEqual ( mutation . args [ 0 ] , index )
366
336
} )
367
- var r = arr . $replace ( expected , arg )
337
+ var r = arr . $remove ( expected )
368
338
assert . ok ( emitted )
369
339
assert . strictEqual ( r , expected )
370
- assert . strictEqual ( arr [ index ] , arg )
371
- } )
372
-
373
- it ( '$replace (function)' , function ( ) {
374
- arr [ 0 ] = 1
375
- arr [ 1 ] = 2
376
- arr [ 2 ] = 3
377
- var expected = [ 2 , 3 , 3 ] ,
378
- expectRet = [ 1 , 2 ]
379
- var replaced = arr . $replace ( function ( e ) {
380
- if ( e < 3 ) return e + 1
381
- } )
382
- assert . deepEqual ( arr , expected )
383
- assert . deepEqual ( replaced , expectRet )
384
340
} )
385
341
386
342
} )
0 commit comments