forked from remeda/remeda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
isNonNull.test.ts
50 lines (49 loc) · 1.17 KB
/
isNonNull.test.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
import { typesDataProvider } from '../test/types_data_provider';
import { isNonNull } from './isNonNull';
describe('isNonNull', () => {
test('isNonNull": should work as type guard', () => {
const data = typesDataProvider('date');
if (isNonNull(data)) {
expect(data instanceof Date).toEqual(true);
assertType<
| boolean
| string
| { a: string }
| (() => void)
| Array<number>
| Date
| Error
| number
| Promise<number>
| undefined
>(data);
}
});
test('isNonNull: should work as type guard in filter', () => {
const data = [
typesDataProvider('error'),
typesDataProvider('array'),
typesDataProvider('function'),
typesDataProvider('null'),
typesDataProvider('number'),
typesDataProvider('undefined'),
].filter(isNonNull);
expect(data).toHaveLength(5);
assertType<
Array<
| string
| number
| boolean
| {
a: string;
}
| (() => void)
| Array<number>
| Date
| Error
| Promise<number>
| undefined
>
>(data);
});
});