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