-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
}); |