Skip to content

Commit

Permalink
test(case): add test case about frozen
Browse files Browse the repository at this point in the history
  • Loading branch information
unadlib committed Jun 20, 2024
1 parent 34b00c3 commit 04c9ece
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions test/immer-non-support.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-inner-declarations */
/* eslint-disable symbol-description */
/* eslint-disable no-unused-expressions */
/* eslint-disable @typescript-eslint/ban-ts-comment */
Expand Down Expand Up @@ -503,3 +504,65 @@ test('error key setting in array', () => {
}
}
});

test(`Object values of a Map are not frozen anymore #1119`, () => {
{
enableMapSet();

interface Fruit {
key: string;
name: string;
}

const fruits: Fruit[] = [
{ key: 'apple1', name: 'Red Delicious' },
{ key: 'apple2', name: 'Gala' },
];

let products = new Map<string, Fruit>();

function setFruitMap(fruits: Fruit[]): void {
products = produce(products, (draft) => {
draft.clear();
fruits.forEach((fruit) => draft.set(fruit.key, fruit));
});
}

setFruitMap(fruits);

const product = products.get('apple1');
// ! it should be frozen
expect(Object.isFrozen(product)).not.toBeTruthy();
}
{
interface Fruit {
key: string;
name: string;
}

const fruits: Fruit[] = [
{ key: 'apple1', name: 'Red Delicious' },
{ key: 'apple2', name: 'Gala' },
];

let products: Immutable<Map<string, Fruit>> = new Map();

function setFruitMap(fruits: Fruit[]): void {
products = create(
products,
(draft) => {
draft.clear();
fruits.forEach((fruit) => draft.set(fruit.key, fruit));
},
{
enableAutoFreeze: true,
}
);
}

setFruitMap(fruits);

const product = products.get('apple1');
expect(Object.isFrozen(product)).toBeTruthy();
}
});

0 comments on commit 04c9ece

Please sign in to comment.