mirror of
https://github.com/XiaoDaiGua-Ray/ray-template.git
synced 2026-11-20 10:13:35 +08:00
Share workspace packages between Ray Admin and the interactive docs. BREAKING CHANGE: v6 is a new major line. v5 stays on legacy/v5.
34 lines
824 B
TypeScript
34 lines
824 B
TypeScript
import { uuid } from '../../apps/admin/src/utils/basic'
|
|
|
|
describe('uuid', () => {
|
|
it('should return String', () => {
|
|
expectTypeOf(uuid()).toEqualTypeOf<string>()
|
|
})
|
|
|
|
it('the return value should be unique', () => {
|
|
const uuid1 = uuid()
|
|
const uuid2 = uuid()
|
|
|
|
expect(uuid1).not.toBe(uuid2)
|
|
})
|
|
|
|
it('should return a string with length 36', () => {
|
|
const uid = uuid(36)
|
|
|
|
expect(uid.length).toBe(36)
|
|
})
|
|
})
|
|
|
|
it('enforces the requested radix and rejects invalid bounds', () => {
|
|
expect(uuid(16, 1)).toBe('0'.repeat(16))
|
|
expect(uuid(24, 10)).toMatch(/^\d{24}$/)
|
|
expect(uuid(0)).toBe('')
|
|
|
|
for (const radix of [0, -1, 63, 1.1, NaN]) {
|
|
expect(() => uuid(8, radix)).toThrow(RangeError)
|
|
}
|
|
|
|
expect(() => uuid(-1)).toThrow(RangeError)
|
|
expect(() => uuid(Infinity)).toThrow(RangeError)
|
|
})
|