-
Notifications
You must be signed in to change notification settings - Fork 4
/
mapAsync.spec.ts
31 lines (24 loc) · 782 Bytes
/
mapAsync.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
import { Maybe } from '@/src/maybe';
describe('Maybe', () => {
describe('mapAsync', () => {
test('transforms to an Async value when there is a value', async () => {
const sut = Maybe.some('val');
const innerMaybe = await sut
.mapAsync((s) => Promise.resolve(2))
.toPromise();
expect(innerMaybe).toHaveValue(2);
});
test('transforms to a MaybeAsync with no value when there is no value', async () => {
const sut = Maybe.none<number>();
let wasCalled = false;
const innerMaybe = await sut
.mapAsync((s) => {
wasCalled = true;
return Promise.resolve(s);
})
.toPromise();
expect(innerMaybe).toHaveNoValue();
expect(wasCalled).toBe(false);
});
});
});