Skip to content

Commit

Permalink
Validate theme() works in arbitray values (#6852)
Browse files Browse the repository at this point in the history
* add tests to ensure theme value inside arbitrary values work

* update changelog
  • Loading branch information
RobinMalfait authored Jan 3, 2022
1 parent b341813 commit c912434
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Improve `DEBUG` flag ([#6797](https://github.com/tailwindlabs/tailwindcss/pull/6797), [#6804](https://github.com/tailwindlabs/tailwindcss/pull/6804))
- Ensure we can use `<` and `>` characters in modifiers ([#6851](https://github.com/tailwindlabs/tailwindcss/pull/6851))
- Validate `theme()` works in arbitrary values ([#6852](https://github.com/tailwindlabs/tailwindcss/pull/6852))

## [3.0.8] - 2021-12-28

Expand Down
46 changes: 46 additions & 0 deletions tests/arbitrary-values.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,49 @@ it('should support unescaped underscores in URLs', () => {
`)
})
})

it('should be possible to read theme values in arbitrary values (without quotes)', () => {
let config = {
content: [{ raw: html`<div class="w-[theme(spacing.1)] w-[theme(spacing[0.5])]"></div>` }],
theme: {
spacing: {
0.5: 'calc(.5 * .25rem)',
1: 'calc(1 * .25rem)',
},
},
}

return run('@tailwind utilities', config).then((result) => {
return expect(result.css).toMatchFormattedCss(css`
.w-\[theme\(spacing\.1\)\] {
width: calc(1 * 0.25rem);
}
.w-\[theme\(spacing\[0\.5\]\)\] {
width: calc(0.5 * 0.25rem);
}
`)
})
})

it('should be possible to read theme values in arbitrary values (with quotes)', () => {
let config = {
content: [{ raw: html`<div class="w-[theme('spacing.1')] w-[theme('spacing[0.5]')]"></div>` }],
theme: {
spacing: {
0.5: 'calc(.5 * .25rem)',
1: 'calc(1 * .25rem)',
},
},
}

return run('@tailwind utilities', config).then((result) => {
return expect(result.css).toMatchFormattedCss(css`
.w-\[theme\(\'spacing\.1\'\)\] {
width: calc(1 * 0.25rem);
}
.w-\[theme\(\'spacing\[0\.5\]\'\)\] {
width: calc(0.5 * 0.25rem);
}
`)
})
})

0 comments on commit c912434

Please sign in to comment.