import { isValidColor } from ".."; describe("isValidColor", () => { it("returns true for valid hex colors", () => { const validHexColors = ["#fff", "#ffffff", "#FF0000", "#000", "#abc123"]; expect.assertions(validHexColors.length); validHexColors.forEach((color) => { expect(isValidColor(color)).toBe(true); }); }); it("returns true for valid rgb and rgba colors", () => { const validRgbColors = [ "rgb(255,0,0)", "rgb(255, 0, 0)", "rgba(255,0,0,0.5)", "rgba(255, 0, 0, 0.5)", ]; expect.assertions(validRgbColors.length); validRgbColors.forEach((color) => { expect(isValidColor(color)).toBe(true); }); }); it("returns true for valid named and special CSS colors", () => { const validNamedColors = ["red", "transparent", "currentColor", "inherit"]; expect.assertions(validNamedColors.length); validNamedColors.forEach((color) => { expect(isValidColor(color)).toBe(true); }); }); it("returns true for valid hsl colors", () => { expect(isValidColor("hsl(0, 100%, 50%)")).toBe(true); }); it("returns false for invalid color strings", () => { const invalidColors = [ "invalid", "", "#gggggg", "#fff.00", "unset", undefined, null, ]; expect.assertions(invalidColors.length); invalidColors.forEach((color) => { expect(isValidColor(color)).toBe(false); }); }); it("returns true for valid rgb and rgba colors", () => { const validRgbColors = ["rgba(239,239,239,1.0)"]; expect.assertions(validRgbColors.length); validRgbColors.forEach((color) => { expect(isValidColor(color)).toBe(true); }); }); });