-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcheckIf.spec.ts
57 lines (49 loc) · 1.79 KB
/
checkIf.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { Result } from '@/src/result';
describe('Result', () => {
describe('checkIf', () => {
describe('condition', () => {
test('will return the original Result without executing the check if the condition is false', () => {
let wasCalled = false;
const check = (num: number) => {
wasCalled = true;
return Result.success(num + 1);
};
const sut = Result.success(1);
expect(sut.checkIf(false, check)).toSucceedWith(1);
expect(wasCalled).toBe(false);
});
test('will return the original Result and execute the check if the condition is true', () => {
let wasCalled = false;
const check = (num: number) => {
wasCalled = true;
return Result.success(num + 1);
};
const sut = Result.success(1);
expect(sut.checkIf(true, check)).toSucceedWith(1);
expect(wasCalled).toBe(true);
});
});
describe('factory', () => {
test('will return the original Result without executing the check if the factory returns false', () => {
let wasCalled = false;
const check = (num: number) => {
wasCalled = true;
return Result.success(num + 1);
};
const sut = Result.success(1);
expect(sut.checkIf(() => false, check)).toSucceedWith(1);
expect(wasCalled).toBe(false);
});
test('will return the original Result and execute the check if the factory returns true', () => {
let wasCalled = false;
const check = (num: number) => {
wasCalled = true;
return Result.success(num + 1);
};
const sut = Result.success(1);
expect(sut.checkIf(() => true, check)).toSucceedWith(1);
expect(wasCalled).toBe(true);
});
});
});
});