This repository was archived by the owner on Aug 31, 2023. It is now read-only.
generated from esdmr/template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnullables.ts
75 lines (65 loc) · 1.67 KB
/
nullables.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { test } from 'tap';
import { testDetail } from '#test/test-util/format.js';
import * as nullables from '#src/nullables.js';
import * as messages from '#src/messages.js';
await test('isNotNull', async (t) => {
t.throws(
() => {
nullables.isNotNull(null);
},
new TypeError(messages.isNull),
'expected to throw an error if the value is null',
);
t.doesNotThrow(
() => {
nullables.isNotNull(undefined);
},
'expected to not throw an error if the value is not null',
);
await testDetail(t, (...args) => {
nullables.isNotNull(null, ...args);
}, TypeError, messages.isNull);
});
await test('isNonNullable', async (t) => {
t.throws(
() => {
nullables.isNonNullable(null);
},
new TypeError(messages.isNullable),
'expected to throw an error if the value is null',
);
t.throws(
() => {
nullables.isNonNullable(undefined);
},
new TypeError(messages.isNullable),
'expected to throw an error if the value is undefined',
);
t.doesNotThrow(
() => {
nullables.isNonNullable(123);
},
'expected to not throw an error if the value is not nullable',
);
await testDetail(t, (...args) => {
nullables.isNonNullable(undefined, ...args);
}, TypeError, messages.isNullable);
});
await test('isNotUndefined', async (t) => {
t.throws(
() => {
nullables.isNotUndefined(undefined);
},
new TypeError(messages.isUndefined),
'expected to throw an error if the value is undefined',
);
t.doesNotThrow(
() => {
nullables.isNotUndefined(null);
},
'expected to not throw an error if the value is not undefined',
);
await testDetail(t, (...args) => {
nullables.isNotUndefined(undefined, ...args);
}, TypeError, messages.isUndefined);
});