-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmapAsync.spec.ts
More file actions
31 lines (25 loc) · 823 Bytes
/
Copy pathmapAsync.spec.ts
File metadata and controls
31 lines (25 loc) · 823 Bytes
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 { Result } from '@/src/result';
describe('Result', () => {
describe('mapAsync', () => {
test('will map to a new asynchronous value with a successful Result', async () => {
const sut = Result.success(1);
const result = await sut
.mapAsync((num) => Promise.resolve(num + 1))
.toPromise();
expect(result).toSucceedWith(2);
});
test('will not execute the mapping with a failed Result', async () => {
let wasCalled = false;
const error = 'error';
const sut = Result.failure<number>(error);
const result = await sut
.mapAsync((num) => {
wasCalled = true;
return Promise.resolve(num + 1);
})
.toPromise();
expect(result).toFailWith(error);
expect(wasCalled).toBe(false);
});
});
});