-
Notifications
You must be signed in to change notification settings - Fork 20
/
46-map-set.js
39 lines (29 loc) · 1.06 KB
/
46-map-set.js
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
// 46: Map.prototype.set()
// To do: make all tests pass, leave the assert lines unchanged!
describe('`Map.prototype.set` adds a new element with key and value to a Map', function(){
it('simplest use case is `set(key, value)` and `get(key)`', function() {
let map = new Map();
map.set('key','value');
assert.equal(map.get('key'), 'value');
});
it('the key can be a complex type too', function() {
const noop = function() {};
let map = new Map();
map.set(noop, 'the real noop');
assert.equal(map.get(noop), 'the real noop');
});
it('calling `set()` again with the same key replaces the value', function() {
let map = new Map();
map.set('key', 'value');
map.set('key', 'value1');
assert.equal(map.get('key'), 'value1');
});
it('`set()` returns the map object, it`s chainable', function() {
let map = new Map();
map.set(1, 'one')
.set(2, 'two')
.set(3, 'three');
assert.deepEqual([...map.keys()], [1,2,3]);
assert.deepEqual([...map.values()], ['one', 'two', 'three']);
});
});