Skip to content

Commit

Permalink
chore: add tests to check the theme config
Browse files Browse the repository at this point in the history
  • Loading branch information
halvaradop committed Oct 7, 2024
1 parent cce2bf3 commit 2a35e9e
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion packages/tailwindcss-animations/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { describe, test, expect } from "vitest"
import { extractClasses } from "@halvaradop/tailwindcss-core/utils"
import plugin from "../src/index.js"
import { plugin } from "../src/index.js"
import { toSlashCase } from "../src/utils.js"
import { theme } from "../src/theme.js"

export const generateClasses = extractClasses(plugin)

Expand All @@ -11,9 +12,15 @@ describe("Plugin", () => {
const html = `<div class="animation-delay-100"></div>`
const css = await generateClasses(html)
expect(css).toMatch(".animation-delay-100{animation-delay:100ms}")
expect(css).not.toMatch(".animation-delay-200{animation-delay:200ms}")
})
})

test("Loaded keyframes utility classes", async () => {
expect(plugin.config?.theme?.keyframes).toEqual(theme.keyframes)
expect(plugin.config?.theme?.keyframes).not.toEqual({})
})

describe("Conflict prevention", () => {
test.concurrent("should not create conflicting classes", async () => {
const html = `<div class="w-full px-2 flex items-center"></div>`
Expand Down Expand Up @@ -56,6 +63,31 @@ describe("Animate delay utility classes", () => {
})
})

describe("Keyframes utility classes", () => {
const testCases = [
{
className: "animate-fade-in",
expected: "@keyframes fade-in{0%{opacity:0}100%{opacity:1}}",
},
{
className: "animate-fade-out",
expected: "@keyframes fade-out{0%{opacity:1}100%{opacity:0}}",
},
{
className: "animate-rotate-90",
expected: "@keyframes rotate-90{0%{transform:rotate(0deg)}100%{transform:rotate(90deg)}}",
},
]

testCases.forEach(({ className, expected }) => {
test.concurrent(`keyframes with class ${className}`, async () => {
const html = `<div class="${className}"></div>`
const css = await generateClasses(html)
expect(css).toMatch(expected)
})
})
})

describe("toSlashCase", () => {
const testCases = [
{ input: "animation", expected: "animation" },
Expand Down

0 comments on commit 2a35e9e

Please sign in to comment.