This repository was archived by the owner on Jun 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.test.js
More file actions
106 lines (84 loc) · 2.42 KB
/
index.test.js
File metadata and controls
106 lines (84 loc) · 2.42 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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
const sut = require('./dist');
const test = require('tape');
const td = require('testdouble');
const not_a_function = 42;
test('throws when dispatcher is not a function', t => {
t.throws( () => sut
( not_a_function
, 5, x => x
, x => x
)
, 'dispatcher is not a function'
);
t.end();
});
test('throws when fallback is not a function', t => {
t.throws( () => sut
( x => x
, 5, x => x
)
, 'fallback is missing'
);
t.throws( () => sut
( x => x
, 5, x => x
, not_a_function
)
, 'fallback is not a function'
);
t.end();
});
test('throws when a handler is not a function', t => {
t.throws( () => sut
( x => x
, 5, x => x
, 6, not_a_function
, 7, x => x
, x => x
)
, 'handler is not a function'
);
t.end();
});
test('applies dispatcher to the arguments given to the multifunction', t => {
const dispatcher = td.function();
td.when(dispatcher(1, 2, 3)).thenReturn(5);
const multifn = sut
( dispatcher
, 5, () => 'OK!'
, x => x
);
t.equal(multifn(1, 2, 3), 'OK!');
t.end();
});
test('applies handler to the arguments given to the multifunction', t => {
const handler = td.function();
td.when(handler(1, 2, 3)).thenReturn('OK!');
const multifn = sut
( () => 5
, 5, handler
, x => x
);
t.equal(multifn(1, 2, 3), 'OK!');
t.end();
});
test('applies fallback to the arguments given to the multifunction', t => {
const fallback = td.function();
td.when(fallback(1, 2, 3)).thenReturn('OK!');
const multifn = sut
( () => 42
, 5, x => x
, fallback
);
t.equal(multifn(1, 2, 3), 'OK!');
t.end();
});
test('uses strict equality when comparing with the dispatched value', t => {
const multifn = sut
( () => 5
, '5', () => 'NOT OK!'
, () => 'OK!'
);
t.equal(multifn(), 'OK!');
t.end();
});