-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmap.test.ts
56 lines (52 loc) · 1.41 KB
/
map.test.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
50
51
52
53
54
55
56
describe('Map', () => {
it('should create a map', () => {
const map = new Map([
['one', 1],
['two', 2],
]);
expect(map).toBeInstanceOf(Map);
expect(map.size).toBe(2);
expect(map.has('one')).toBe(true);
expect(map.has('two')).toBe(true);
expect(map.has('three')).toBe(false);
expect(map.get('one')).toBe(1);
expect(map.get('two')).toBe(2);
expect(map.get('three')).toBeUndefined();
map.set('one', -1);
expect(map.get('one')).toBe(-1);
map.delete('one');
expect(map.get('one')).toBeUndefined();
});
it('Map.keys()', () => {
const map1 = new Map([
['one', 1],
['two', 2],
]);
const keys1 = map1.keys();
expect(keys1.next().value).toBe('one');
expect(keys1.next().value).toBe('two');
map1.delete('one');
const keys2 = map1.keys();
expect(keys2.next().value).toBe('two');
expect(keys2.next().value).toBeUndefined();
});
it('Map.entries()', () => {
const map1 = new Map([
['one', 1],
['two', 2],
]);
const entries1 = map1.entries();
expect(entries1.next().value).toEqual(['one', 1]);
expect(entries1.next().value).toEqual(['two', 2]);
});
it('Map.values()', () => {
const map1 = new Map([
['one', 1],
['two', 2],
]);
const entries1 = map1.values();
expect(entries1.next().value).toEqual(1);
expect(entries1.next().value).toEqual(2);
});
});
export {};