@@ -263,44 +263,96 @@ describe('UNIT: Observer', function () {
263263 } )
264264
265265 describe ( 'Augmentations' , function ( ) {
266+
267+ it ( 'remove (index)' , function ( ) {
268+ var emitted = false ,
269+ index = ~ ~ ( Math . random ( ) * arr . length ) ,
270+ expected = arr [ index ] = { a : 1 }
271+ ob . once ( 'mutate' , function ( key , array , mutation ) {
272+ emitted = true
273+ assert . strictEqual ( mutation . method , 'splice' )
274+ assert . strictEqual ( mutation . args . length , 2 )
275+ assert . strictEqual ( mutation . args [ 0 ] , index )
276+ } )
277+ var r = arr . remove ( index )
278+ assert . ok ( emitted )
279+ assert . strictEqual ( r , expected )
280+ } )
266281
267- it ( 'remove' , function ( ) {
282+ it ( 'remove (object) ' , function ( ) {
268283 var emitted = false ,
269- expected = arr [ 0 ] = { a : 1 }
284+ index = ~ ~ ( Math . random ( ) * arr . length ) ,
285+ expected = arr [ index ] = { a : 1 }
270286 ob . once ( 'mutate' , function ( key , array , mutation ) {
271287 emitted = true
272288 assert . strictEqual ( mutation . method , 'splice' )
273289 assert . strictEqual ( mutation . args . length , 2 )
290+ assert . strictEqual ( mutation . args [ 0 ] , index )
274291 } )
275292 var r = arr . remove ( expected )
276293 assert . ok ( emitted )
277294 assert . strictEqual ( r , expected )
278295 } )
279296
280- it ( 'replace' , function ( ) {
297+ it ( 'remove (function)' , function ( ) {
298+ var expected = [ 1001 , 1002 ]
299+ arr . push . apply ( arr , expected )
300+ var filter = function ( e ) {
301+ return e > 1000
302+ } ,
303+ copy = arr . filter ( function ( e ) {
304+ return e <= 1000
305+ } )
306+ var removed = arr . remove ( filter )
307+ assert . deepEqual ( arr , copy )
308+ assert . deepEqual ( expected , removed )
309+ } )
310+
311+ it ( 'replace (index)' , function ( ) {
312+ var emitted = false ,
313+ index = ~ ~ ( Math . random ( ) * arr . length ) ,
314+ expected = arr [ index ] = { a : 1 } ,
315+ arg = 34567
316+ ob . once ( 'mutate' , function ( key , array , mutation ) {
317+ emitted = true
318+ assert . strictEqual ( mutation . method , 'splice' )
319+ assert . strictEqual ( mutation . args . length , 3 )
320+ assert . strictEqual ( mutation . args [ 0 ] , index )
321+ } )
322+ var r = arr . replace ( index , arg )
323+ assert . ok ( emitted )
324+ assert . strictEqual ( r , expected )
325+ assert . strictEqual ( arr [ index ] , arg )
326+ } )
327+
328+ it ( 'replace (object)' , function ( ) {
281329 var emitted = false ,
282- expected = arr [ 0 ] = { a : 1 } ,
330+ index = ~ ~ ( Math . random ( ) * arr . length ) ,
331+ expected = arr [ index ] = { a : 1 } ,
283332 arg = 45678
284333 ob . once ( 'mutate' , function ( key , array , mutation ) {
285334 emitted = true
286335 assert . strictEqual ( mutation . method , 'splice' )
287336 assert . strictEqual ( mutation . args . length , 3 )
337+ assert . strictEqual ( mutation . args [ 0 ] , index )
288338 } )
289339 var r = arr . replace ( expected , arg )
290340 assert . ok ( emitted )
291341 assert . strictEqual ( r , expected )
292- assert . strictEqual ( arr [ 0 ] , arg )
342+ assert . strictEqual ( arr [ index ] , arg )
293343 } )
294344
295- it ( 'mutateFilter' , function ( ) {
296- var filter = function ( e ) {
297- return e > 1000
298- } ,
299- copy = arr . slice ( ) . filter ( filter )
300- arr . mutateFilter ( filter )
301- for ( var i = 0 ; i < copy . length ; i ++ ) {
302- assert . strictEqual ( arr [ i ] , copy [ i ] )
303- }
345+ it ( 'replace (function)' , function ( ) {
346+ arr [ 0 ] = 1
347+ arr [ 1 ] = 2
348+ arr [ 2 ] = 3
349+ var expected = [ 2 , 3 , 3 ] ,
350+ expectRet = [ 1 , 2 ]
351+ var replaced = arr . replace ( function ( e ) {
352+ if ( e < 3 ) return e + 1
353+ } )
354+ assert . deepEqual ( arr , expected )
355+ assert . deepEqual ( replaced , expectRet )
304356 } )
305357
306358 } )
0 commit comments