Skip to content

Commit 6f314e3

Browse files
authored
chore: add tests to check the theme config (#74)
* chore: add tests to check the theme config * chore: add `utils.test.ts` file * chore: remove `addUtilitiesRegex`
1 parent cce2bf3 commit 6f314e3

File tree

3 files changed

+52
-22
lines changed

3 files changed

+52
-22
lines changed

packages/tailwindcss-animations/src/utils.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,6 @@
1010
*/
1111
export const matchUtilitiesRegex = new RegExp(/^(animation(?=Delay|Duration|Steps|IterationCount|FillMode|Range))/)
1212

13-
/**
14-
* Match utilities that are generated by addUtilities function provided by TailwindCSS.
15-
* @example
16-
*
17-
* // Expected: true
18-
* addUtilitiesRegex.test("animation")
19-
*
20-
* // Expected: false
21-
* addUtilitiesRegex.test("animation-delay-100")
22-
*/
23-
export const addUtilitiesRegex = new RegExp(/^(animation|keyframes|animationCubicBezier)/)
24-
2513
/**
2614
* Converts a camelCase string to a slash-case string.
2715
*

packages/tailwindcss-animations/test/index.test.ts

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { describe, test, expect } from "vitest"
22
import { extractClasses } from "@halvaradop/tailwindcss-core/utils"
3-
import plugin from "../src/index.js"
4-
import { toSlashCase } from "../src/utils.js"
3+
import { plugin } from "../src/index.js"
4+
import { theme } from "../src/theme.js"
55

66
export const generateClasses = extractClasses(plugin)
77

@@ -11,9 +11,15 @@ describe("Plugin", () => {
1111
const html = `<div class="animation-delay-100"></div>`
1212
const css = await generateClasses(html)
1313
expect(css).toMatch(".animation-delay-100{animation-delay:100ms}")
14+
expect(css).not.toMatch(".animation-delay-200{animation-delay:200ms}")
1415
})
1516
})
1617

18+
test("Loaded keyframes utility classes", async () => {
19+
expect(plugin.config?.theme?.keyframes).toEqual(theme.keyframes)
20+
expect(plugin.config?.theme?.keyframes).not.toEqual({})
21+
})
22+
1723
describe("Conflict prevention", () => {
1824
test.concurrent("should not create conflicting classes", async () => {
1925
const html = `<div class="w-full px-2 flex items-center"></div>`
@@ -56,17 +62,27 @@ describe("Animate delay utility classes", () => {
5662
})
5763
})
5864

59-
describe("toSlashCase", () => {
65+
describe("Keyframes utility classes", () => {
6066
const testCases = [
61-
{ input: "animation", expected: "animation" },
62-
{ input: "animationDelay", expected: "animation-delay" },
63-
{ input: "animationDuration", expected: "animation-duration" },
64-
{ input: "animationIterationCount", expected: "animation-iteration-count" },
67+
{
68+
className: "animate-fade-in",
69+
expected: "@keyframes fade-in{0%{opacity:0}100%{opacity:1}}",
70+
},
71+
{
72+
className: "animate-fade-out",
73+
expected: "@keyframes fade-out{0%{opacity:1}100%{opacity:0}}",
74+
},
75+
{
76+
className: "animate-rotate-90",
77+
expected: "@keyframes rotate-90{0%{transform:rotate(0deg)}100%{transform:rotate(90deg)}}",
78+
},
6579
]
6680

67-
testCases.forEach(({ input, expected }) => {
68-
test(`converts ${input} to ${expected}`, () => {
69-
expect(toSlashCase(input)).toBe(expected)
81+
testCases.forEach(({ className, expected }) => {
82+
test.concurrent(`keyframes with class ${className}`, async () => {
83+
const html = `<div class="${className}"></div>`
84+
const css = await generateClasses(html)
85+
expect(css).toMatch(expected)
7086
})
7187
})
7288
})
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { describe, test, expect } from "vitest"
2+
import { toSlashCase, matchUtilitiesRegex } from "../src/utils.js"
3+
4+
describe("toSlashCase", () => {
5+
const testCases = [
6+
{ input: "animation", expected: "animation" },
7+
{ input: "animationDelay", expected: "animation-delay" },
8+
{ input: "animationDuration", expected: "animation-duration" },
9+
{ input: "animationIterationCount", expected: "animation-iteration-count" },
10+
]
11+
12+
testCases.forEach(({ input, expected }) => {
13+
test(`converts ${input} to ${expected}`, () => {
14+
expect(toSlashCase(input)).toBe(expected)
15+
})
16+
})
17+
})
18+
19+
describe("matchUtilitiesRegex", () => {
20+
test("matches animation utilities", () => {
21+
expect(matchUtilitiesRegex.test("animationDelay")).toBe(true)
22+
expect(matchUtilitiesRegex.test("animationDuration")).toBe(true)
23+
expect(matchUtilitiesRegex.test("animation")).toBe(false)
24+
expect(matchUtilitiesRegex.test("keyframes")).toBe(false)
25+
})
26+
})

0 commit comments

Comments
 (0)