Skip to content

Commit

Permalink
add: util tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Aman035 committed Sep 9, 2024
1 parent fbccddb commit fd73237
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions packages/core/tests/utils/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { getRandomElement } from '../../src/lib/utils';

describe('getRandomElement', () => {
it('should return a valid element (Small Array ~ 1k elements)', () => {
const testArray = Array.from(
{ length: 1000 },
(_, i) => `https://validator/${i}`
);
const element = getRandomElement(testArray);
expect(testArray).toContain(element);
});

it('should return a valid element (Large Array ~ 10k elements)', () => {
const testArray = Array.from(
{ length: 10000 },
(_, i) => `https://validator/${i}`
);
const element = getRandomElement(testArray);
expect(testArray).toContain(element);
});

it('should return a valid element (Large Array ~ 100k elements)', () => {
const testArray = Array.from(
{ length: 100000 },
(_, i) => `https://validator/${i}`
);
const element = getRandomElement(testArray);
expect(testArray).toContain(element);
});

it('should throw an error if array length is 0', () => {
expect(() => getRandomElement([])).toThrow('Array cannot be empty');
});
});

0 comments on commit fd73237

Please sign in to comment.