Skip to content

Commit 0f6811a

Browse files
committed
test(tapEither): additional assertions, test cases
1 parent 6074548 commit 0f6811a

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

test/result/tapEither.spec.ts

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ describe('Result', () => {
99
sut.tapEither(() => (wasCalled = true));
1010

1111
expect(wasCalled).toBe(true);
12+
expect(sut).toSucceedWith(1);
1213
});
1314

1415
test('will execute the given action if the Result is a failure', () => {
@@ -18,6 +19,7 @@ describe('Result', () => {
1819
sut.tapEither(() => (wasCalled = true));
1920

2021
expect(wasCalled).toBe(true);
22+
expect(sut).toFailWith('error');
2123
});
2224
});
2325
});

test/result/tapEitherAsync.spec.ts

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ describe('Result', () => {
1515
await sut.tapEitherAsync(asyncAction).toPromise();
1616

1717
expect(wasCalled).toBe(true);
18+
expect(sut).toSucceedWith(1);
1819
});
1920

2021
test('will execute the asynchronous action if the Result is a failure', async () => {
@@ -29,6 +30,7 @@ describe('Result', () => {
2930
await sut.tapEitherAsync(asyncAction).toPromise();
3031

3132
expect(wasCalled).toBe(true);
33+
expect(sut).toFailWith('error');
3234
});
3335
});
3436
});

test/resultAsync/tapEither.spec.ts

+18
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,23 @@ describe('ResultAsync', () => {
4949
expect(result).toSucceedWith(1);
5050
expect(wasCalled).toBe(true);
5151
});
52+
53+
test('executes the async action with a failed ResultAsync', async () => {
54+
const error = 'error';
55+
let wasCalled = false;
56+
57+
const sut = ResultAsync.failure(error);
58+
59+
const result = await sut
60+
.tapEither(() => {
61+
wasCalled = true;
62+
63+
return Promise.resolve();
64+
})
65+
.toPromise();
66+
67+
expect(result).toFailWith(error);
68+
expect(wasCalled).toBe(true);
69+
});
5270
});
5371
});

0 commit comments

Comments
 (0)