-
Notifications
You must be signed in to change notification settings - Fork 4
/
map.spec.ts
40 lines (30 loc) · 1.04 KB
/
map.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
import { ResultAsync } from '@/src/resultAsync';
describe('ResultAsync', () => {
describe('map', () => {
test('calls the projection with a successful ResultAsync', async () => {
const value = 1;
const sut = ResultAsync.success(value);
const result = await sut.map((num) => num + 1).toPromise();
expect(result).toSucceedWith(2);
});
test('does not call the projection with a failed ResultAsync', async () => {
let wasCalled = false;
const sut = ResultAsync.failure<number>('error');
const result = await sut
.map((num) => {
wasCalled = true;
return num + 1;
})
.toPromise();
expect(result).toFailWith('error');
expect(wasCalled).toBe(false);
});
test('calls a Promise returning projection with a successful ResultAsync', async () => {
const sut = ResultAsync.success(1);
const result = await sut
.map((num) => Promise.resolve(num + 1))
.toPromise();
expect(result).toSucceedWith(2);
});
});
});