@@ -735,3 +735,69 @@ test('Unexpected undefined not assigned', () => {
735735 expect ( Object . prototype . hasOwnProperty . call ( foo , 'name' ) ) . toBe ( true ) ;
736736 }
737737} ) ;
738+
739+ test ( 'apply - map with object key' , ( ) => {
740+ {
741+ enablePatches ( ) ;
742+ enableMapSet ( ) ;
743+ const key = { id : 1 } ;
744+ const base = {
745+ map : new Map ( [ [ key , { value : 1 } ] ] ) ,
746+ } ;
747+ const [ next , patches , inverse ] = produceWithPatches ( base , ( draft ) => {
748+ draft . map . get ( key ) ! . value = 2 ;
749+ } ) ;
750+ expect ( ( ) => applyPatches ( base , patches ) ) . toThrow ( ) ;
751+ expect ( ( ) => applyPatches ( next , inverse ) ) . toThrow ( ) ;
752+ }
753+ {
754+ const key = { id : 1 } ;
755+ const base = {
756+ map : new Map ( [ [ key , { value : 1 } ] ] ) ,
757+ } ;
758+ const [ next , patches , inverse ] = create (
759+ base ,
760+ ( draft ) => {
761+ draft . map . get ( key ) ! . value = 2 ;
762+ } ,
763+ { enablePatches : true }
764+ ) ;
765+ expect ( apply ( base , patches ) ) . toEqual ( next ) ;
766+ expect ( apply ( next , inverse ) ) . toEqual ( base ) ;
767+ }
768+ } ) ;
769+
770+ test ( 'apply - symbol key on object' , ( ) => {
771+ {
772+ enablePatches ( ) ;
773+ const sym = Symbol ( 'key' ) ;
774+ const base = {
775+ obj : {
776+ [ sym ] : { value : 1 } ,
777+ } ,
778+ } ;
779+ const [ next , patches , inverse ] = produceWithPatches ( base , ( draft ) => {
780+ draft . obj [ sym ] . value = 2 ;
781+ } ) ;
782+ expect ( ( ) => applyPatches ( base , patches ) ) . toThrow ( ) ;
783+ expect ( ( ) => applyPatches ( next , inverse ) ) . toThrow ( ) ;
784+ }
785+ {
786+ const sym = Symbol ( 'key' ) ;
787+ const base = {
788+ obj : {
789+ [ sym ] : { value : 1 } ,
790+ } ,
791+ } ;
792+ const [ next , patches , inverse ] = create (
793+ base ,
794+ ( draft ) => {
795+ draft . obj [ sym ] . value = 2 ;
796+ } ,
797+ { enablePatches : true }
798+ ) ;
799+ expect ( apply ( base , patches ) ) . toEqual ( next ) ;
800+ expect ( apply ( next , inverse ) ) . toEqual ( base ) ;
801+ }
802+ } ) ;
803+
0 commit comments