/ opencodehub / src / lib / utils.test.ts
swadhinbiswas Initial commit of OpenCodeHub source · 12/11/2025
1110042
33 lines · 835 Bytes
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
import { describe, expect, it } from "vitest";
import { generateId, slugify } from "./utils";

describe("utils", () => {
  describe("generateId", () => {
    it("should generate a string", () => {
      expect(typeof generateId()).toBe("string");
    });

    it("should generate unique ids", () => {
      expect(generateId()).not.toBe(generateId());
    });

    it("should add prefix if provided", () => {
      expect(generateId("user")).toMatch(/^user_/);
    });
  });

  describe("slugify", () => {
    it("should slugify text", () => {
      expect(slugify("Hello World")).toBe("hello-world");
    });

    it("should handle special characters", () => {
      expect(slugify("Hello @ World!")).toBe("hello-world");
    });

    it("should trim dashes", () => {
      expect(slugify("-Hello-")).toBe("hello");
    });
  });
});