-
Notifications
You must be signed in to change notification settings - Fork 1
/
slugify.test.js
40 lines (39 loc) · 1.12 KB
/
slugify.test.js
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
34
35
36
37
38
39
40
import slugify from "../src";
describe("[UT] Slugify", () => {
it("convert to lower case", () => {
expect(slugify("ABC1")).toBe("abc1");
});
it("keep alphanum-_ chars", () => {
expect(slugify("abc- ABC_ 123")).toBe("abc-abc_-123");
});
it("replace space by -", () => {
expect(slugify("a b c")).toBe("a-b-c");
});
it("replace tabs by -", () => {
expect(slugify("a\tb c")).toBe("a-b-c");
});
it("replace new line by -", () => {
expect(slugify("a\nb \n c")).toBe("a-b-c");
});
it("replace special chars by -", () => {
expect(slugify("a~b%%c")).toBe("a-b-c");
});
it("replace unicode chars by -", () => {
expect(slugify("a\u00A9b \u00A9 c")).toBe("a-b-c");
});
it("keep - and _", () => {
expect(slugify("a@-b_=c")).toBe("a-b_-c");
});
it("remove - duplicates", () => {
expect(slugify("a--bc")).toBe("a-bc");
});
it("remove leading -", () => {
expect(slugify("-abc")).toBe("abc");
});
it("remove trailing -", () => {
expect(slugify("abc-")).toBe("abc");
});
it("strip start and end special chars", () => {
expect(slugify("!abc!")).toBe("abc");
});
});