|
| 1 | +import "@testing-library/jest-dom"; |
| 2 | + |
| 3 | +import { cn } from "../cn"; |
| 4 | + |
| 5 | +describe("cn", () => { |
| 6 | + it("should return empty string when no arguments provided", () => { |
| 7 | + expect(cn()).toBe(""); |
| 8 | + }); |
| 9 | + |
| 10 | + it("should return single class name", () => { |
| 11 | + expect(cn("px-4")).toBe("px-4"); |
| 12 | + }); |
| 13 | + |
| 14 | + it("should concatenate multiple class names", () => { |
| 15 | + expect(cn("px-4", "py-2", "rounded")).toBe("px-4 py-2 rounded"); |
| 16 | + }); |
| 17 | + |
| 18 | + it("should handle conditional class names with boolean values", () => { |
| 19 | + // eslint-disable-next-line no-constant-binary-expression |
| 20 | + expect(cn("px-4", true && "py-2", false && "rounded")).toBe("px-4 py-2"); |
| 21 | + }); |
| 22 | + |
| 23 | + it("should handle undefined and null values", () => { |
| 24 | + expect(cn("px-4", undefined, null, "py-2")).toBe("px-4 py-2"); |
| 25 | + }); |
| 26 | + |
| 27 | + it("should handle objects with conditional classes", () => { |
| 28 | + expect(cn({ "px-4": true, "py-2": false, rounded: true })).toBe( |
| 29 | + "px-4 rounded" |
| 30 | + ); |
| 31 | + }); |
| 32 | + |
| 33 | + it("should handle arrays of class names", () => { |
| 34 | + expect(cn(["px-4", "py-2", "rounded"])).toBe("px-4 py-2 rounded"); |
| 35 | + }); |
| 36 | + |
| 37 | + it("should handle mixed arguments", () => { |
| 38 | + expect( |
| 39 | + cn( |
| 40 | + "base", |
| 41 | + { "px-4": true, "py-2": false }, |
| 42 | + ["rounded", "shadow"], |
| 43 | + undefined, |
| 44 | + "text-sm" |
| 45 | + ) |
| 46 | + ).toBe("base px-4 rounded shadow text-sm"); |
| 47 | + }); |
| 48 | + |
| 49 | + it("should handle empty strings", () => { |
| 50 | + expect(cn("px-4", "", "py-2")).toBe("px-4 py-2"); |
| 51 | + }); |
| 52 | + |
| 53 | + it("should deduplicate class names", () => { |
| 54 | + expect(cn("px-4", "py-2", "px-4")).toBe("py-2 px-4"); |
| 55 | + }); |
| 56 | +}); |
0 commit comments