-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
52 lines (40 loc) · 1.13 KB
/
test.js
File metadata and controls
52 lines (40 loc) · 1.13 KB
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
require('es6-shim')
const test = require('tape')
const mapmaker = require('./')
test('returns a map', function(t) {
const map = mapmaker({abc: 'def', 123: 456})
const keys = []
const iter = map.keys()
keys.push(iter.next().value)
keys.push(iter.next().value)
keys.sort()
t.ok(map instanceof Map)
t.deepEqual(keys, ['123', 'abc'])
t.equal(map.get('abc'), 'def')
t.equal(map.get('123'), 456)
t.equal(map.size, 2)
t.ok(map.has('123'))
t.notOk(map.has('456'))
t.end()
})
test('works for iterables', function(t) {
const map = mapmaker({abc: 'def', 123: 456})
const mapmap = mapmaker(map)
const setmap = mapmaker(new Set([
['abc', 'def'], [123, 456]
]))
t.ok(map instanceof Map)
t.ok(mapmap instanceof Map)
t.equal(mapmap.size, 2)
t.ok(setmap instanceof Map)
t.equal(mapmap.size, 2)
t.end()
})
test('TypeError for non-object', function(t) {
t.throws(mapmaker.bind(null, 2), TypeError)
t.throws(mapmaker.bind(null, undefined), TypeError)
t.throws(mapmaker.bind(null, null), TypeError)
t.throws(mapmaker.bind(null, 'str'), TypeError)
t.throws(mapmaker.bind(null, true), TypeError)
t.end()
})