-
Notifications
You must be signed in to change notification settings - Fork 4
/
bind.spec.ts
36 lines (28 loc) · 912 Bytes
/
bind.spec.ts
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
import { Maybe } from '@/src/maybe';
describe('Maybe', () => {
describe('bind', () => {
test('converts the Maybes inner value to a new Maybe with a value', () => {
const value = 1;
const otherValue = 'hello';
const sut = Maybe.some(value);
expect(sut.bind((number) => Maybe.some(number + otherValue))).toHaveValue(
`${value}${otherValue}`
);
});
test('converts the Maybes inner value to a new Maybe with no value', () => {
const value = 1;
const sut = Maybe.some(value);
expect(sut.bind((_) => Maybe.none<string>())).toHaveNoValue();
});
test('performs no action for Maybes with no value', () => {
const sut = Maybe.none<number>();
let wasCalled = false;
expect(
sut.bind((_) => {
wasCalled = true;
return Maybe.some('test');
})
).toHaveNoValue();
});
});
});