/
index.spec.ts
29 lines (28 loc) · 979 Bytes
/
index.spec.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 { getName } from '../../test/util';
import { sampleSize } from '.';
describe(getName(__filename), () => {
describe('sampleSize', () => {
const array = ['a', 'b', 'c', 'd'];
it('returns correct sized array', () => {
expect(sampleSize(array, 2)).toHaveLength(2);
});
it('returns full array for undefined number', () => {
expect(sampleSize(array, undefined)).toEqual(array);
});
it('returns full array for null number', () => {
expect(sampleSize(array, null)).toEqual([]);
});
it('returns full array for 0 number', () => {
expect(sampleSize(array, 0)).toEqual([]);
});
it('returns empty array for null array', () => {
expect(sampleSize(null, 1)).toEqual([]);
});
it('returns empty array for undefined array', () => {
expect(sampleSize(undefined, 1)).toEqual([]);
});
it('returns empty array for empty array', () => {
expect(sampleSize([], 1)).toEqual([]);
});
});
});