2024-07-29 16:14:12 +02:00
|
|
|
import { describe, expect, it } from 'vitest'
|
2022-10-18 15:53:43 +02:00
|
|
|
import { getRandomBytes } from '../dist/index.js'
|
|
|
|
|
|
|
|
describe('Random', () => {
|
|
|
|
it('Should be able to create random values', async () => {
|
|
|
|
const buffer = await getRandomBytes(8)
|
2024-07-29 16:14:12 +02:00
|
|
|
expect(buffer).instanceOf(Uint8Array)
|
|
|
|
expect(buffer.byteLength).toEqual(8)
|
2022-10-18 15:53:43 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should throw error on empty array', async () => {
|
2024-07-29 16:14:12 +02:00
|
|
|
await expect(() => getRandomBytes(0)).rejects.toThrowErrorMatchingSnapshot()
|
2022-10-18 15:53:43 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
it('Should throw error on negative bytes', async () => {
|
2024-07-29 16:14:12 +02:00
|
|
|
await expect(() => getRandomBytes(-1)).rejects.toThrowErrorMatchingSnapshot()
|
2022-10-18 15:53:43 +02:00
|
|
|
})
|
|
|
|
})
|