forked from remeda/remeda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
isNot.test.ts
52 lines (50 loc) · 1.22 KB
/
isNot.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
51
52
import { isNot } from './isNot';
import { isPromise } from './isPromise';
import { isString } from './isString';
import { typesDataProvider } from '../test/types_data_provider';
describe('isNot', () => {
test('isNot: should work as type guard', () => {
const data = typesDataProvider('promise');
if (isNot(isString)(data)) {
expect(data instanceof Promise).toEqual(true);
assertType<
| number
| boolean
| {
a: string;
}
| (() => void)
| Array<number>
| Date
| Error
| Promise<number>
| null
| undefined
>(data);
}
});
test('isNot: should work as type guard in filter', () => {
const data = [
typesDataProvider('promise'),
typesDataProvider('array'),
typesDataProvider('boolean'),
typesDataProvider('function'),
];
const result = data.filter(isNot(isPromise));
expect(result.some(c => c instanceof Promise)).toEqual(false);
assertType<
Array<
| boolean
| string
| { a: string }
| (() => void)
| Array<number>
| Date
| undefined
| null
| Error
| number
>
>(result);
});
});