-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbindAsync.spec.ts
45 lines (34 loc) · 1.22 KB
/
bindAsync.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
37
38
39
40
41
42
43
44
45
import { Maybe } from '@/src/maybe';
import { MaybeAsync } from '@/src/maybeAsync';
describe('Maybe', () => {
describe('bindAsync', () => {
test('converts the Maybes inner value to a new MaybeAsync with a value', async () => {
const value = 1;
const otherValue = 'hello';
const sut = Maybe.some(value);
const innerMaybe = await sut
.bindAsync((number) => MaybeAsync.some(number + otherValue))
.toPromise();
expect(innerMaybe).toHaveValue(`${value}${otherValue}`);
});
test('converts the Maybes inner value to a new MaybeAsync with no value', async () => {
const value = 1;
const sut = Maybe.some(value);
const innerMaybe = await sut
.bindAsync((_) => MaybeAsync.none<string>())
.toPromise();
expect(innerMaybe).toHaveNoValue();
});
test('performs no action and returns a MaybeAsync with no value for Maybes with no value', async () => {
const sut = Maybe.none<number>();
let wasCalled = false;
const innerMaybe = await sut
.bindAsync((_) => {
wasCalled = true;
return MaybeAsync.some('test');
})
.toPromise();
expect(innerMaybe).toHaveNoValue();
});
});
});