|
| 1 | +/* eslint-disable no-inner-declarations */ |
1 | 2 | /* eslint-disable symbol-description */ |
2 | 3 | /* eslint-disable no-unused-expressions */ |
3 | 4 | /* eslint-disable @typescript-eslint/ban-ts-comment */ |
@@ -503,3 +504,65 @@ test('error key setting in array', () => { |
503 | 504 | } |
504 | 505 | } |
505 | 506 | }); |
| 507 | + |
| 508 | +test(`Object values of a Map are not frozen anymore #1119`,()=>{ |
| 509 | +{ |
| 510 | +enableMapSet(); |
| 511 | + |
| 512 | +interfaceFruit{ |
| 513 | +key:string; |
| 514 | +name:string; |
| 515 | +} |
| 516 | + |
| 517 | +constfruits:Fruit[]=[ |
| 518 | +{key:'apple1',name:'Red Delicious'}, |
| 519 | +{key:'apple2',name:'Gala'}, |
| 520 | +]; |
| 521 | + |
| 522 | +letproducts=newMap<string,Fruit>(); |
| 523 | + |
| 524 | +functionsetFruitMap(fruits:Fruit[]):void{ |
| 525 | +products=produce(products,(draft)=>{ |
| 526 | +draft.clear(); |
| 527 | +fruits.forEach((fruit)=>draft.set(fruit.key,fruit)); |
| 528 | +}); |
| 529 | +} |
| 530 | + |
| 531 | +setFruitMap(fruits); |
| 532 | + |
| 533 | +constproduct=products.get('apple1'); |
| 534 | +// ! it should be frozen |
| 535 | +expect(Object.isFrozen(product)).not.toBeTruthy(); |
| 536 | +} |
| 537 | +{ |
| 538 | +interfaceFruit{ |
| 539 | +key:string; |
| 540 | +name:string; |
| 541 | +} |
| 542 | + |
| 543 | +constfruits:Fruit[]=[ |
| 544 | +{key:'apple1',name:'Red Delicious'}, |
| 545 | +{key:'apple2',name:'Gala'}, |
| 546 | +]; |
| 547 | + |
| 548 | +letproducts:Immutable<Map<string,Fruit>>=newMap(); |
| 549 | + |
| 550 | +functionsetFruitMap(fruits:Fruit[]):void{ |
| 551 | +products=create( |
| 552 | +products, |
| 553 | +(draft)=>{ |
| 554 | +draft.clear(); |
| 555 | +fruits.forEach((fruit)=>draft.set(fruit.key,fruit)); |
| 556 | +}, |
| 557 | +{ |
| 558 | +enableAutoFreeze:true, |
| 559 | +} |
| 560 | +); |
| 561 | +} |
| 562 | + |
| 563 | +setFruitMap(fruits); |
| 564 | + |
| 565 | +constproduct=products.get('apple1'); |
| 566 | +expect(Object.isFrozen(product)).toBeTruthy(); |
| 567 | +} |
| 568 | +}); |