-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtapAsync.spec.ts
35 lines (27 loc) · 923 Bytes
/
tapAsync.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
import { Result } from '@/src/result';
describe('Result', () => {
describe('tapAsync', () => {
describe('promise', () => {
test('will execute the asynchronous action if the Result is successful', async () => {
let wasCalled = false;
const sut = Result.success(1);
const asyncAction = () => {
wasCalled = true;
return Promise.resolve();
};
await sut.tapAsync(asyncAction).toPromise();
expect(wasCalled).toBe(true);
});
test('will not execute the asynchronous action if the Result is a failure', async () => {
let wasCalled = false;
const sut = Result.failure<number>('error');
const asyncAction = () => {
wasCalled = true;
return Promise.resolve();
};
await sut.tapAsync(asyncAction).toPromise();
expect(wasCalled).toBe(false);
});
});
});
});