-
Notifications
You must be signed in to change notification settings - Fork 13
/
case-nested-object.ts
49 lines (45 loc) · 1.27 KB
/
case-nested-object.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { runTestSuit } from '../_util';
runTestSuit(
'case-object-nested',
'case nested',
() => {
// base data
const mapBase = new Map<string, any>([
[
'key1',
{
id: 1,
a: { b: [{ b1: [{ c1: 1 }] }], b_rest: { r1: 1 } },
rest: { r1: 1 },
},
],
[
'key2',
{
id: 1,
a: { b: [{ b1: [{ c1: 1 }] }], b_rest: { r1: 1 } },
rest: { r1: 1 },
},
],
]);
return mapBase;
},
(draft) => {
// change draft
draft.get('key1').a.b[0].b1[0].c1 = 2;
},
(mapFinal, mapBase) => {
// asset
expect(mapFinal === mapBase).toBeFalsy();
const key1Value = mapBase.get('key1');
const key1NewValue = mapFinal.get('key1');
expect(key1Value === key1NewValue).toBeFalsy();
expect(key1Value.a === key1NewValue.a).toBeFalsy();
expect(key1Value.a.b === key1NewValue.a.b).toBeFalsy();
expect(key1Value.a.b_rest === key1NewValue.a.b_rest).toBeTruthy();
expect(key1Value.rest === key1NewValue.rest).toBeTruthy();
expect(mapBase.get('key1').a.b[0].b1[0].c1 === 1).toBeTruthy();
expect(mapFinal.get('key1').a.b[0].b1[0].c1 === 2).toBeTruthy();
expect(mapBase.get('key2') === mapBase.get('key2')).toBeTruthy();
},
);