-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmatch.spec.ts
More file actions
65 lines (51 loc) · 1.48 KB
/
Copy pathmatch.spec.ts
File metadata and controls
65 lines (51 loc) · 1.48 KB
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
58
59
60
61
62
63
64
65
import { MaybeAsync } from '@/src/maybeAsync';
describe('MaybeAsync', () => {
describe('match:void', () => {
test('will call the some callback when there is a value', async () => {
const value = 1;
const sut = MaybeAsync.some(value);
let capturedValue = 0;
await sut.match({
some: (number) => {
capturedValue = number;
},
none: () => {
capturedValue = 10;
},
});
expect(capturedValue).toBe(value);
});
test('will call the none callback when there is no value', async () => {
const value = 10;
const sut = MaybeAsync.none<number>();
let capturedValue = 0;
await sut.match({
some: (_) => {
capturedValue = 1;
},
none: () => {
capturedValue = value;
},
});
expect(capturedValue).toBe(value);
});
});
describe('match:value', () => {
test('will return the value from the some callback when there is a value', async () => {
const sut = MaybeAsync.some(1);
const result = await sut.match({
some: (_) => 'some',
none: () => 'none',
});
expect(result).toBe('some');
});
test('will return the value from the non callback when there is no value', async () => {
const sut = MaybeAsync.none<number>();
const result = await sut.match({
some: (_) => 'some',
none: () => 'none',
});
expect(result).toBe('none');
});
});
});