Skip to content

Commit

Permalink
Add test for slugify
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchernchong committed Nov 22, 2024
1 parent d9be335 commit 5131428
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/utils/__tests__/slugify.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { describe, expect, it } from "vitest";
import { deslugify, slugify } from "../slugify";

describe("slugify", () => {
it("should convert basic string to slug", () => {
expect(slugify("Hello World")).toBe("hello-world");
});

it("should handle multiple spaces and special chars", () => {
expect(slugify("My Example!!! URL")).toBe("my-example-url");
});

it("should handle numbers correctly", () => {
expect(slugify("Article 123")).toBe("article-123");
});

it("should trim leading and trailing spaces", () => {
expect(slugify(" Trim Spaces ")).toBe("trim-spaces");
});

it("should handle consecutive special characters", () => {
expect(slugify("Multiple!!!Special***Chars")).toBe(
"multiple-special-chars",
);
});

it("should handle empty string", () => {
expect(slugify("")).toBe("");
});

it("should maintain correct order of words", () => {
expect(slugify("First Second Third")).toBe("first-second-third");
});
});

describe("deslugify", () => {
it("should convert basic slug to readable string", () => {
expect(deslugify("hello-world")).toBe("Hello World");
});

it("should handle numbers in slug", () => {
expect(deslugify("article-123")).toBe("Article 123");
});

it("should handle single word", () => {
expect(deslugify("hello")).toBe("Hello");
});

it("should handle empty string", () => {
expect(deslugify("")).toBe("");
});

it("should handle multiple consecutive hyphens", () => {
expect(deslugify("multiple--hyphens")).toBe("Multiple Hyphens");
});

it("should maintain correct capitalization for each word", () => {
expect(deslugify("first-second-third")).toBe("First Second Third");
});
});

0 comments on commit 5131428

Please sign in to comment.