Skip to content

Commit e936a00

Browse files
committed
add more variant tests for the new API
1 parent 0a4a064 commit e936a00

File tree

1 file changed

+119
-1
lines changed

1 file changed

+119
-1
lines changed

tests/variants.test.js

Lines changed: 119 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from 'fs'
22
import path from 'path'
33

4-
import { run, css } from './util/run'
4+
import { run, css, html } from './util/run'
55

66
test('variants', () => {
77
let config = {
@@ -24,6 +24,124 @@ test('variants', () => {
2424
})
2525
})
2626

27+
test('order matters and produces different behaviour', () => {
28+
let config = {
29+
content: [
30+
{
31+
raw: html`
32+
<div class="hover:file:bg-pink-600"></div>
33+
<div class="file:hover:bg-pink-600"></div>
34+
`,
35+
},
36+
],
37+
}
38+
39+
return run('@tailwind utilities', config).then((result) => {
40+
return expect(result.css).toMatchFormattedCss(css`
41+
.hover\\:file\\:bg-pink-600::file-selector-button:hover {
42+
--tw-bg-opacity: 1;
43+
background-color: rgb(219 39 119 / var(--tw-bg-opacity));
44+
}
45+
46+
.file\\:hover\\:bg-pink-600:hover::file-selector-button {
47+
--tw-bg-opacity: 1;
48+
background-color: rgb(219 39 119 / var(--tw-bg-opacity));
49+
}
50+
`)
51+
})
52+
})
53+
54+
describe('custom advanced variants', () => {
55+
test('prose-headings usage on its own', () => {
56+
let config = {
57+
content: [
58+
{
59+
raw: html` <div class="prose-headings:text-center"></div> `,
60+
},
61+
],
62+
plugins: [
63+
function ({ addVariant }) {
64+
addVariant('prose-headings', ({ format }) => {
65+
return format(':where(&) :is(h1, h2, h3, h4)')
66+
})
67+
},
68+
],
69+
}
70+
71+
return run('@tailwind components;@tailwind utilities', config).then((result) => {
72+
return expect(result.css).toMatchFormattedCss(css`
73+
:where(.prose-headings\\:text-center) :is(h1, h2, h3, h4) {
74+
text-align: center;
75+
}
76+
`)
77+
})
78+
})
79+
80+
test('prose-headings with another "simple" variant', () => {
81+
let config = {
82+
content: [
83+
{
84+
raw: html`
85+
<div class="hover:prose-headings:text-center"></div>
86+
<div class="prose-headings:hover:text-center"></div>
87+
`,
88+
},
89+
],
90+
plugins: [
91+
function ({ addVariant }) {
92+
addVariant('prose-headings', ({ format }) => {
93+
return format(':where(&) :is(h1, h2, h3, h4)')
94+
})
95+
},
96+
],
97+
}
98+
99+
return run('@tailwind components;@tailwind utilities', config).then((result) => {
100+
return expect(result.css).toMatchFormattedCss(css`
101+
:where(.hover\\:prose-headings\\:text-center) :is(h1, h2, h3, h4):hover {
102+
text-align: center;
103+
}
104+
105+
:where(.prose-headings\\:hover\\:text-center:hover) :is(h1, h2, h3, h4) {
106+
text-align: center;
107+
}
108+
`)
109+
})
110+
})
111+
112+
test('prose-headings with another "complex" variant', () => {
113+
let config = {
114+
content: [
115+
{
116+
raw: html`
117+
<div class="group-hover:prose-headings:text-center"></div>
118+
<div class="prose-headings:group-hover:text-center"></div>
119+
`,
120+
},
121+
],
122+
plugins: [
123+
function ({ addVariant }) {
124+
addVariant('prose-headings', ({ format }) => {
125+
return format(':where(&) :is(h1, h2, h3, h4)')
126+
})
127+
},
128+
],
129+
}
130+
131+
return run('@tailwind utilities', config).then((result) => {
132+
return expect(result.css).toMatchFormattedCss(css`
133+
.group:hover :where(.group-hover\\:prose-headings\\:text-center) :is(h1, h2, h3, h4) {
134+
text-align: center;
135+
}
136+
137+
:where(.group:hover .prose-headings\\:group-hover\\:text-center) :is(h1, h2, h3, h4) {
138+
text-align: center;
139+
}
140+
`)
141+
})
142+
})
143+
})
144+
27145
test('stacked peer variants', async () => {
28146
let config = {
29147
content: [{ raw: 'peer-disabled:peer-focus:peer-hover:border-blue-500' }],

0 commit comments

Comments
 (0)