UNPKG

@awal-solution/tailwind-theming

Version:

<div align="left"> <h1>Tailwind theming</h1> <p>The <b>TailwindCSS Multi-Theming Plugin</b> is a utility for creating and managing multiple themes in your TailwindCSS-based projects. With this library, you can define, add, update, and remove themes dyn

83 lines (82 loc) 2.62 kB
import { themePlugin as d } from "../plugin/index.js"; describe("themePlugin", () => { let e, o; beforeEach(() => { e = { addVariant: jest.fn(), addBase: jest.fn(), addUtilities: jest.fn(), e: jest.fn((a) => a) }, o = [ { name: "light-theme", selectors: [":root", '[data-theme="light-theme"]'], extend: { colors: { background: "#ffffff", foreground: "#000000" } } }, { name: "dark-theme", selectors: [".dark-theme", '[data-theme="dark-theme"]'], extend: { colors: { background: "#000000", foreground: "#ffffff" } } } ]; }), test("should add theme variants correctly", () => { const t = d({ themes: o }).handler; t(e), expect(e.addVariant).toHaveBeenCalledTimes(3), expect(e.addVariant).toHaveBeenCalledWith( "light-theme", expect.arrayContaining([":root &", "&:root"]) ), expect(e.addVariant).toHaveBeenCalledWith( "dark-theme", expect.arrayContaining([".dark-theme &", "&.dark-theme"]) ); }), test("should add theme styles correctly", () => { const t = d({ themes: o }).handler; t(e), expect(e.addBase).toHaveBeenCalledTimes(3), expect(e.addBase).toHaveBeenCalledWith({ ':root, [data-theme="light-theme"]': expect.any(Object) }), expect(e.addBase).toHaveBeenCalledWith({ '.dark-theme, [data-theme="dark-theme"]': expect.any(Object) }); }), test("should add utilities if provided", () => { const t = d({ utilities: { ".text-primary": { color: "#ff5722" } } }).handler; t(e), expect(e.addUtilities).toHaveBeenCalledTimes(1), expect(e.addUtilities).toHaveBeenCalledWith({ ".text-primary": { color: "#ff5722" } }); }), test("should return correct theme extensions", () => { var n, r; const t = (r = (n = d({ themes: o }).config) == null ? void 0 : n.theme) == null ? void 0 : r.extend; expect(t).toBeDefined(), expect(t == null ? void 0 : t.colors).toMatchObject({ background: "rgb(var(--colors-background) / <alpha-value>)", foreground: "rgb(var(--colors-foreground) / <alpha-value>)" }); }); }); describe("themePlugin edge cases", () => { test("should handle missing selectors gracefully", () => { const e = { themes: [ { name: "theme-without-selectors", extend: { colors: { primary: "#fff" } } } ] }, { handler: o } = d(e); expect(() => o).not.toThrow(); }); });