-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
36 lines (30 loc) · 798 Bytes
/
test.js
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
import test from 'ava';
import arrayChunks from './';
test('size smaller than array length', t => {
t.same(arrayChunks([1, 2, 3, 4, 5], 2), [[1, 2], [3, 4], [5]]);
});
test('size larger than array length', t => {
t.same(arrayChunks([1, 2, 3, 4, 5], 6), [[1, 2, 3, 4, 5]]);
});
test('work with TypedArray', t => {
if (Int8Array !== undefined) {
arrayChunks(new Int8Array([1, 2, 3, 4, 5]), 2)
.forEach((item, idx) => {
if (idx !== 2) {
t.same(item.length, 2);
} else {
t.same(item.length, 1);
}
})
} else {
t.pass();
}
});
test('throw error when passed in non-array variable', t => {
t.throws(() => {
arrayChunks(123, 4);
}, 'Input should be Array or TypedArray');
t.notThrows(() => {
arrayChunks([123], 4);
});
});