hash.test.ts 582 B

12345678910111213141516171819202122
  1. import { describe, expect, it } from 'vitest';
  2. import { generateUUID } from './hash';
  3. describe('generateUUID', () => {
  4. it('should return a string', () => {
  5. const uuid = generateUUID();
  6. expect(typeof uuid).toBe('string');
  7. });
  8. it('should be length 32', () => {
  9. const uuid = generateUUID();
  10. expect(uuid.length).toBe(36);
  11. });
  12. it('should have the correct format', () => {
  13. const uuid = generateUUID();
  14. const uuidRegex =
  15. /^[\da-f]{8}-[\da-f]{4}-4[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i;
  16. expect(uuidRegex.test(uuid)).toBe(true);
  17. });
  18. });