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 failing tests
  • Loading branch information
RobinMalfait committed Feb 20, 2025
commit 132071d9ac683a45f32a3ab81f725975c42c6a67
84 changes: 80 additions & 4 deletions packages/tailwindcss/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1021,8 +1021,7 @@ describe('sorting', () => {
})
})

// Parsing theme values from CSS
describe('Parsing themes values from CSS', () => {
describe('Parsing theme values from CSS', () => {
test('Can read values from `@theme`', async () => {
expect(
await compileCss(
Expand Down Expand Up @@ -2020,7 +2019,44 @@ describe('Parsing themes values from CSS', () => {
`)
})

test('`@media theme(…)` can only contain `@theme` rules', () => {
test('`@import "tailwindcss" theme(static)` will always generate theme values, regardless of whether they were used or not', async () => {
expect(
await compileCss(
css`
@import 'tailwindcss' theme(static);
`,
['bg-tomato'],
{
async loadStylesheet() {
return {
content: css`
@theme {
--color-tomato: #e10c04;
--color-potato: #ac855b;
--color-primary: var(--primary);
}

@tailwind utilities;
`,
base: '',
}
},
},
),
).toMatchInlineSnapshot(`
":root, :host {
--color-tomato: #e10c04;
--color-potato: #ac855b;
--color-primary: var(--primary);
}

.bg-tomato {
background-color: var(--color-tomato);
}"
`)
})

test('`@media theme(reference)` can only contain `@theme` rules', () => {
return expect(
compileCss(
css`
Expand All @@ -2034,7 +2070,10 @@ describe('Parsing themes values from CSS', () => {
['bg-tomato', 'bg-potato', 'bg-avocado'],
),
).rejects.toThrowErrorMatchingInlineSnapshot(
`[Error: Files imported with \`@import "…" theme(…)\` must only contain \`@theme\` blocks.]`,
`
[Error: Files imported with \`@import "…" theme(reference)\` must only contain \`@theme\` blocks.
Use \`@reference "…";\` instead.]
`,
)
})

Expand Down Expand Up @@ -2073,6 +2112,43 @@ describe('Parsing themes values from CSS', () => {
`)
})

test('`@import "tailwindcss" theme(inline)` theme values added as `inline` are not wrapped in `var(…)` when used as utility values', async () => {
expect(
await compileCss(
css`
@import 'tailwindcss' theme(inline);
`,
['bg-tomato'],
{
async loadStylesheet() {
return {
content: css`
@theme {
--color-tomato: #e10c04;
--color-potato: #ac855b;
--color-primary: var(--primary);
}

@tailwind utilities;
`,
base: '',
}
},
},
),
).toMatchInlineSnapshot(`
":root, :host {
--color-tomato: #e10c04;
--color-potato: #ac855b;
--color-primary: var(--primary);
}

.bg-tomato {
background-color: #e10c04;
}"
`)
})

test('theme values added as `static` will always be generated, regardless of whether they were used or not', async () => {
expect(
await compileCss(
Expand Down