@@ -2926,8 +2926,8 @@ test('#18 - map: assigning a non-draft with the same key - enablePatches', () =>
2926
2926
) ;
2927
2927
expect ( created [ 0 ] . map . get ( 0 ) . one . two ) . toBe ( 2 ) ;
2928
2928
2929
- // expect(apply(baseState, created[1])).toEqual(created[0]);
2930
- // expect(apply(created[0], created[2])).toEqual(baseState);
2929
+ expect ( apply ( baseState , created [ 1 ] ) ) . toEqual ( created [ 0 ] ) ;
2930
+ expect ( apply ( created [ 0 ] , created [ 2 ] ) ) . toEqual ( baseState ) ;
2931
2931
} ) ;
2932
2932
2933
2933
test ( '#18 - set: assigning a non-draft with the same key' , ( ) => {
@@ -3002,3 +3002,42 @@ test('#18 - array: assigning a non-draft with the same key - enablePatches', ()
3002
3002
expect ( apply ( baseState , created [ 1 ] ) ) . toEqual ( created [ 0 ] ) ;
3003
3003
expect ( apply ( created [ 0 ] , created [ 2 ] ) ) . toEqual ( baseState ) ;
3004
3004
} ) ;
3005
+
3006
+ test ( '#18: assigning a non-draft with the different key - enablePatches' , ( ) => {
3007
+ const baseState = {
3008
+ array : [
3009
+ {
3010
+ one : {
3011
+ two : 3 ,
3012
+ } ,
3013
+ } ,
3014
+ ] ,
3015
+ } ;
3016
+
3017
+ const created = create (
3018
+ baseState ,
3019
+ ( draft ) => {
3020
+ draft . array [ 0 ] . one . two = 2 ;
3021
+ // @ts -ignore
3022
+ draft . array1 = [ 0 , { c : draft . array [ 0 ] } ] ;
3023
+ // @ts -ignore
3024
+ draft . map = [ 0 , new Map ( [ [ 0 , draft . array [ 0 ] ] ] ) ] ;
3025
+ // @ts -ignore
3026
+ draft . set = [ 0 , new Set ( [ draft . array [ 0 ] ] ) ] ;
3027
+ } ,
3028
+ {
3029
+ enablePatches : true ,
3030
+ }
3031
+ ) ;
3032
+ // @ts -ignore
3033
+ expect ( created [ 0 ] . array [ 0 ] . one . two ) . toBe ( 2 ) ;
3034
+ // @ts -ignore
3035
+ expect ( created [ 0 ] . array1 [ 1 ] . c . one . two ) . toBe ( 2 ) ;
3036
+ // @ts -ignore
3037
+ expect ( created [ 0 ] . map [ 1 ] . get ( 0 ) . one . two ) . toBe ( 2 ) ;
3038
+ // @ts -ignore
3039
+ expect ( Array . from ( created [ 0 ] . set [ 1 ] ) [ 0 ] . one . two ) . toBe ( 2 ) ;
3040
+
3041
+ expect ( apply ( baseState , created [ 1 ] ) ) . toEqual ( created [ 0 ] ) ;
3042
+ expect ( apply ( created [ 0 ] , created [ 2 ] ) ) . toEqual ( baseState ) ;
3043
+ } ) ;
0 commit comments