-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwc.test.js
102 lines (85 loc) · 3.57 KB
/
twc.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// twc.test.js
const twc = require("./twc");
describe("twc function", () => {
it("should merge class names without conditional classes", () => {
const result = twc("bg-blue-500", "text-white", "p-4");
expect(result).toBe("bg-blue-500 text-white p-4");
});
it("should merge class names with conditional classes (true)", () => {
const isActive = true;
const result = twc("bg-blue-500", "text-white", { "font-bold": isActive });
expect(result).toBe("bg-blue-500 text-white font-bold");
});
it("should merge class names with conditional classes (false)", () => {
const isActive = false;
const result = twc("bg-blue-500", "text-white", { "font-bold": isActive });
expect(result).toBe("bg-blue-500 text-white");
});
it("should handle null and undefined values", () => {
const result = twc("bg-blue-500", null, undefined, "p-4");
expect(result).toBe("bg-blue-500 p-4");
});
it("should handle numbers as class names", () => {
const result = twc(42, "text-red-500", 7);
expect(result).toBe("42 text-red-500 7");
});
it("should handle boolean values", () => {
const result = twc("bg-blue-500", true, false);
expect(result).toBe("bg-blue-500");
});
it("should handle an object with multiple classes", () => {
const classes = {
"text-green-500": true,
"font-bold": false,
"p-2": true,
};
const result = twc("bg-yellow-300", classes);
expect(result).toBe("bg-yellow-300 text-green-500 p-2");
});
it("should handle an array of class names", () => {
const result = twc("bg-blue-500", ["text-white", "p-4"]);
expect(result).toBe("bg-blue-500 text-white p-4");
});
it("should handle an array of class names with conditional classes", () => {
const isActive = true;
const result = twc("bg-blue-500", [
"text-white",
{ "font-bold": isActive },
]);
expect(result).toBe("bg-blue-500 text-white font-bold");
});
it("should handle an array of class names with null and undefined values", () => {
const result = twc("bg-blue-500", ["text-white", null, undefined, "p-4"]);
expect(result).toBe("bg-blue-500 text-white p-4");
});
it("should handle an array of class names with numbers as class names", () => {
const result = twc("bg-blue-500", [42, "text-red-500", 7]);
expect(result).toBe("bg-blue-500 42 text-red-500 7");
});
it("should handle an array of class names with boolean values", () => {
const result = twc("bg-blue-500", [true, false]);
expect(result).toBe("bg-blue-500");
});
it("should handle an array of class names with an object with multiple classes", () => {
const classes = {
"text-green-500": true,
"font-bold": false,
"p-2": true,
};
const result = twc("bg-yellow-300", ["text-white", classes]);
expect(result).toBe("bg-yellow-300 text-green-500 p-2");
});
it("should handle an array of class names with an array of class names", () => {
const result = twc("bg-blue-500", ["text-white", ["p-4"]]);
expect(result).toBe("bg-blue-500 text-white p-4");
});
it("should handle an array of class names with an array of class names with conditional classes", () => {
const isActive = true;
const result = twc("bg-blue-500", ["text-white", ["font-bold", isActive]]);
expect(result).toBe("bg-blue-500 text-white font-bold");
});
it("should handle an array of class names with an array of class names with null and undefined values", () => {
const result = twc("bg-blue-500", ["text-white", ["p-4", null, undefined]]);
expect(result).toBe("bg-blue-500 text-white p-4");
});
});