-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcompensate.spec.ts
31 lines (23 loc) · 1011 Bytes
/
compensate.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
import { Result } from '@/src/result';
describe('Result', () => {
describe('compensate', () => {
test('takes the result from the second result, when previous result fails', () => {
const sut = Result.failure('💥');
expect(sut.compensate(() => Result.success('✅'))).toSucceedWith('✅');
});
test('takes the result from the first result, when it succeeds', () => {
const sut = Result.success('✅');
expect(sut.compensate(() => Result.failure('💥'))).toSucceedWith('✅');
});
test('takes the failure from the second result, when both fail', () => {
const sut = Result.failure('💥');
expect(sut.compensate(() => Result.failure('💥💥'))).toFailWith('💥💥');
});
test('calls projection with first result error', () => {
const sut = Result.failure('💥');
const projection = vi.fn(() => Result.success('✅'));
sut.compensate(projection);
expect(projection).toBeCalledWith('💥');
});
});
});