renovate/lib/util/index.spec.ts
RahulGautamSingh 3d31fa371d
refactor(lib/util): strict null check for test files (#15812)
* add types for tmp

* expand files in lib/util

* update yarn lock

* Update tsconfig.strict.json

* util/exec

* util/git

* util/http

* Revert "util/exec"

This reverts commit 96cf479a1b.

* update strict.json

* redo util/exec

* revert util/git

* util/merge-confidence

* update util/git

* util/package-rules

* fix util/git

* util/template

* util/

* revert extras

* rm newline

* add tmp back

* apply suggestion from review

* util/cache

* more changes

* Update tsconfig.strict.json

Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
2022-06-19 21:17:46 +00:00

35 lines
997 B
TypeScript

import { sampleSize } from '.';
describe('util/index', () => {
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 as never)).toEqual(array);
});
it('returns full array for null number', () => {
expect(sampleSize(array, null as never)).toBeEmptyArray();
});
it('returns full array for 0 number', () => {
expect(sampleSize(array, 0)).toBeEmptyArray();
});
it('returns empty array for null array', () => {
expect(sampleSize(null as never, 1)).toBeEmptyArray();
});
it('returns empty array for undefined array', () => {
expect(sampleSize(undefined as never, 1)).toBeEmptyArray();
});
it('returns empty array for empty array', () => {
expect(sampleSize([], 1)).toBeEmptyArray();
});
});
});