forked from remeda/remeda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
isArray.test.ts
29 lines (27 loc) · 916 Bytes
/
isArray.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
import { isArray } from './isArray';
import { typesDataProvider } from '../test/types_data_provider';
describe('isArray', () => {
test('isArray: should work as type guard', () => {
const data = typesDataProvider('array');
if (isArray(data)) {
expect(Array.isArray(data)).toEqual(true);
assertType<Array<number>>(data);
}
const data1: unknown = typesDataProvider('array');
if (isArray(data1)) {
assertType<ReadonlyArray<unknown>>(data1);
}
});
test('isArray: should work as type guard in filter', () => {
const data = [
typesDataProvider('error'),
typesDataProvider('array'),
typesDataProvider('function'),
typesDataProvider('null'),
typesDataProvider('array'),
typesDataProvider('date'),
].filter(isArray);
expect(data.every(c => Array.isArray(c))).toEqual(true);
assertType<Array<Array<number>>>(data);
});
});