Skip to content

Commit bc0f59e

Browse files
committed
add tests to verify fallback plugins
1 parent c500d8a commit bc0f59e

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed

tests/arbitrary-values.test.css

+6
Original file line numberDiff line numberDiff line change
@@ -652,9 +652,15 @@
652652
.bg-\[\#0f0_var\(--value\)\] {
653653
background-color: #0f0 var(--value);
654654
}
655+
.bg-\[var\(--value1\)_var\(--value2\)\] {
656+
background-color: var(--value1) var(--value2);
657+
}
655658
.bg-\[color\:var\(--value1\)_var\(--value2\)\] {
656659
background-color: var(--value1) var(--value2);
657660
}
661+
.bg-\[var\(--value\)\2c var\(--value\)\] {
662+
background-color: var(--value), var(--value);
663+
}
658664
.bg-opacity-\[0\.11\] {
659665
--tw-bg-opacity: 0.11;
660666
}

tests/arbitrary-values.test.js

+51-4
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,58 @@ it('should not convert escaped underscores with spaces', () => {
262262
})
263263
})
264264

265-
it('should warn and not generate if arbitrary values are ambiguous', () => {
266-
// If we don't protect against this, then `bg-[200px_100px]` would both
267-
// generate the background-size as well as the background-position utilities.
265+
it('should pick the fallback plugin when arbitrary values collide', () => {
268266
let config = {
269-
content: [{ raw: html`<div class="bg-[200px_100px]"></div>` }],
267+
content: [
268+
{
269+
raw: html`
270+
<div>
271+
<!-- Background color -->
272+
<div class="bg-[var(--unknown)]"></div>
273+
<!-- Background size -->
274+
<div class="bg-[200px_100px]"></div>
275+
</div>
276+
`,
277+
},
278+
],
279+
}
280+
281+
return run('@tailwind utilities', config).then((result) => {
282+
return expect(result.css).toMatchFormattedCss(css`
283+
.bg-\[var\(--unknown\)\] {
284+
background-color: var(--unknown);
285+
}
286+
287+
.bg-\[200px_100px\] {
288+
background-size: 200px 100px;
289+
}
290+
`)
291+
})
292+
})
293+
294+
it('should pick the fallback plugin when arbitrary values collide and can not be inferred', () => {
295+
let config = {
296+
content: [{ raw: html`<div class="bg-[var(--tw-unknown)]"></div>` }],
297+
}
298+
299+
return run('@tailwind utilities', config).then((result) => {
300+
return expect(result.css).toMatchFormattedCss(css`
301+
.bg-\[var\(--tw-unknown\)\] {
302+
background-color: var(--tw-unknown);
303+
}
304+
`)
305+
})
306+
})
307+
308+
it('should warn and not generate if arbitrary values are ambiguous (without fallback)', () => {
309+
let config = {
310+
content: [{ raw: html`<div class="foo-[200px_100px]"></div>` }],
311+
plugins: [
312+
function ({ matchUtilities }) {
313+
matchUtilities({ foo: (value) => ({ value }) }, { type: ['position'] })
314+
matchUtilities({ foo: (value) => ({ value }) }, { type: ['length'] })
315+
},
316+
],
270317
}
271318

272319
return run('@tailwind utilities', config).then((result) => {

0 commit comments

Comments
 (0)