-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.js
87 lines (62 loc) · 1.56 KB
/
tests.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const test = require( 'tape' )
const formats = [require('./script.js')]
try {
require('./module_test.js')
formats.push(require('./module.js'))
}
catch(e){}
formats.forEach(give => {
test(
"When called on a Map without an entry for the supplied key",
assert => {
assert.test(
"assigns the output of the supplied factory to that key, with key and Map supplied to factory",
assert => {
const map = new Map()
give(map, 'foo', (x, y) => {
assert.equal(x, 'foo')
assert.equal(y, map)
return 'bar'
})
assert.equals(map.get('foo'), 'bar')
assert.end()
}
)
assert.test(
"returns the value",
assert => {
assert.equals(
give( new Map(), 'foo', () => 'bar' ),
'bar'
)
assert.end()
}
)
}
)
test(
"When called on a Map with an entry at the supplied key",
assert => {
const map = new Map().set( 'foo', 'bar' )
assert.test(
"doesn't execute the supplied factory",
assert => {
let executed = false
give( map, 'foo', () => executed = true )
assert.equals( executed, false )
assert.end()
}
)
assert.test(
"returns the value assigned to that key",
assert => {
assert.equals(
give( map, 'foo', () => 'baz' ),
'bar'
)
assert.end()
}
)
}
)
})