-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbind.spec.ts
35 lines (28 loc) · 982 Bytes
/
bind.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('bind', () => {
test('will execute the projection and return a successful Result with a successful Result', () => {
const sut = Result.success(1);
expect(sut.bind((num) => Result.success(num + 1))).toSucceedWith(2);
});
test('will execute the projection and return a failed Result with a successful Result', () => {
const sut = Result.success(1);
const error = 'oops!';
expect(sut.bind((_num) => Result.failure<number>(error))).toFailWith(
error
);
});
test('will not execute the projection with a failed Result', () => {
const error = 'error';
let wasCalled = false;
const sut = Result.failure<number>(error);
expect(
sut.bind((num) => {
wasCalled = true;
return Result.success(num + 1);
})
).toFailWith(error);
expect(wasCalled).toBe(false);
});
});
});