@@ -341,6 +341,18 @@ SAFETY_MODES.forEach((safety) => {
341341 const sig = new Signal ( [ ] , { safety } ) ;
342342 expect ( sig . getID ( 'plain' ) ) . toBe ( 'plain' ) ;
343343 } ) ;
344+
345+ it ( 'treats a falsy-but-present id as the id' , ( ) => {
346+ const sig = new Signal ( [ ] , { safety } ) ;
347+ expect ( sig . getID ( { id : 0 } ) ) . toBe ( 0 ) ;
348+ expect ( sig . getID ( { id : '' } ) ) . toBe ( '' ) ;
349+ } ) ;
350+
351+ it ( 'falls through fields only when the prior is null or undefined' , ( ) => {
352+ const sig = new Signal ( [ ] , { safety } ) ;
353+ expect ( sig . getID ( { id : 0 , _id : 'b' } ) ) . toBe ( 0 ) ;
354+ expect ( sig . getID ( { id : null , _id : 'b' } ) ) . toBe ( 'b' ) ;
355+ } ) ;
344356 } ) ;
345357
346358 describe ( 'getIDs' , ( ) => {
@@ -356,6 +368,11 @@ SAFETY_MODES.forEach((safety) => {
356368 const sig = new Signal ( [ ] , { safety } ) ;
357369 expect ( sig . getIDs ( 'plain' ) ) . toEqual ( [ 'plain' ] ) ;
358370 } ) ;
371+
372+ it ( 'keeps a zero id rather than dropping it' , ( ) => {
373+ const sig = new Signal ( [ ] , { safety } ) ;
374+ expect ( sig . getIDs ( { id : 0 } ) ) . toEqual ( [ 0 ] ) ;
375+ } ) ;
359376 } ) ;
360377
361378 describe ( 'hasID' , ( ) => {
@@ -591,6 +608,19 @@ SAFETY_MODES.forEach((safety) => {
591608 sig . replaceItem ( 'a' , { id : 'a' , v : 100 } ) ;
592609 expect ( sig . raw ( ) ) . toBe ( before ) ;
593610 } ) ;
611+
612+ it ( 'is a no-op when no item matches the id' , ( ) => {
613+ const sig = new Signal (
614+ [ { id : 'a' , v : 1 } , { id : 'b' , v : 2 } ] ,
615+ { safety } ,
616+ ) ;
617+ const sub = subscribe ( sig ) ;
618+ sig . replaceItem ( 'missing' , { id : 'missing' , v : 99 } ) ;
619+ Reaction . flush ( ) ;
620+ expect ( sig . raw ( ) ) . toEqual ( [ { id : 'a' , v : 1 } , { id : 'b' , v : 2 } ] ) ;
621+ expect ( sub . count ) . toBe ( 0 ) ;
622+ sub . stop ( ) ;
623+ } ) ;
594624 } ) ;
595625
596626 describe ( 'removeItem' , ( ) => {
@@ -624,6 +654,19 @@ SAFETY_MODES.forEach((safety) => {
624654 sig . removeItem ( 'b' ) ;
625655 expect ( sig . raw ( ) ) . toBe ( before ) ;
626656 } ) ;
657+
658+ it ( 'is a no-op when no item matches the id (does not delete the last item)' , ( ) => {
659+ const sig = new Signal (
660+ [ { id : 'a' } , { id : 'b' } , { id : 'c' } ] ,
661+ { safety } ,
662+ ) ;
663+ const sub = subscribe ( sig ) ;
664+ sig . removeItem ( 'missing' ) ;
665+ Reaction . flush ( ) ;
666+ expect ( sig . raw ( ) . map ( i => i . id ) ) . toEqual ( [ 'a' , 'b' , 'c' ] ) ;
667+ expect ( sub . count ) . toBe ( 0 ) ;
668+ sub . stop ( ) ;
669+ } ) ;
627670 } ) ;
628671
629672 /*******************************
0 commit comments