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