Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add test for testing error handling for @utility
  • Loading branch information
RobinMalfait committed Sep 26, 2024
commit 190a2669191d85c148c91fd13bfd65e08e840fb9
34 changes: 34 additions & 0 deletions packages/tailwindcss/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2573,6 +2573,40 @@ describe('@variant', () => {
})
})

describe('@utility', () => {
test('@utility must be top-level and cannot be nested', () =>
expect(
compileCss(css`
.foo {
@utility foo {
color: red;
}
}
`),
).rejects.toThrowErrorMatchingInlineSnapshot(`[Error: \`@utility\` cannot be nested.]`))

test('@utility must include a body', () =>
expect(
compileCss(css`
@utility foo {
}
`),
).rejects.toThrowErrorMatchingInlineSnapshot(
`[Error: \`@utility foo\` is empty. Utilities should include at least one property.]`,
))

test('@utility cannot contain any special characters', () =>
expect(
compileCss(css`
@utility 💨 {
color: red;
}
`),
).rejects.toThrowErrorMatchingInlineSnapshot(
`[Error: \`@utility 💨\` defines an invalid utility name. Utilities should be alphanumeric and start with a lowercase letter.]`,
))
})

test('addBase', async () => {
let { build } = await compile(
css`
Expand Down