-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuuid.test.ts
47 lines (40 loc) · 1011 Bytes
/
uuid.test.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import {
test,
expect,
} from "vitest"
import {
randomUUID,
randomUUIDArray,
} from "."
const ITERATIONS = 1_000
const LENGTH = 100
test(`Return an uuid`, () => {
const set = new Set()
for (let i = 0; i < ITERATIONS; i++) {
const value = randomUUID()
expect(set.has(value)).toBeFalsy
set.add(value)
}
})
test(`Return an uuid array of length ${LENGTH}`, () => {
const set = new Set()
for (let i = 0; i < ITERATIONS; i++) {
const values = randomUUIDArray(LENGTH)
expect(values.length).toBe(LENGTH)
values.forEach(value => {
expect(set.has(value)).toBeFalsy
set.add(value)
})
}
})
// error cases
test("Throw error for non numeric string length", () => {
// @ts-ignore
expect(() => randomUUIDArray("10")).toThrow()
})
test("Throw error for negative string length value", () => {
expect(() => randomUUIDArray(-5)).toThrow()
})
test("Throw error for infinite string length value", () => {
expect(() => randomUUIDArray(Infinity)).toThrow()
})