Skip to content

Commit 2febb2a

Browse files
committed
Add more tests
1 parent d737828 commit 2febb2a

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/return.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,37 @@ test('Can return a function from another one', (t) => {
2222
noop,
2323
)
2424
})
25+
26+
test('options.mapReturnValues() can return any type', (t) => {
27+
t.is(
28+
switchFunctional(0, {
29+
mapReturnValues: (condition: number) => -condition,
30+
})
31+
.case(true, 1)
32+
.default(2),
33+
-1,
34+
)
35+
})
36+
37+
test('options.mapReturnValues() can return a function', (t) => {
38+
t.is(
39+
switchFunctional(1, {
40+
mapReturnValues: (condition: number) => (value: number) =>
41+
condition + value,
42+
})
43+
.case(true, 2)
44+
.default(0),
45+
3,
46+
)
47+
})
48+
49+
test('options.mapReturnValues() can take variadic parameters', (t) => {
50+
t.is(
51+
switchFunctional(0, {
52+
mapReturnValues: (one: number, two: number) => one + two,
53+
})
54+
.case(true, 1, 2)
55+
.default(0, 0),
56+
3,
57+
)
58+
})

0 commit comments

Comments
 (0)