Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit04c9ece

Browse files
committed
test(case): add test case about frozen
1 parent34b00c3 commit04c9ece

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

‎test/immer-non-support.test.ts‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-inner-declarations */
12
/* eslint-disable symbol-description */
23
/* eslint-disable no-unused-expressions */
34
/* eslint-disable @typescript-eslint/ban-ts-comment */
@@ -503,3 +504,65 @@ test('error key setting in array', () => {
503504
}
504505
}
505506
});
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+
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp