Skip to content

Commit 69e97df

Browse files
committed
add failing test
1 parent 65dc530 commit 69e97df

File tree

1 file changed

+174
-0
lines changed

1 file changed

+174
-0
lines changed

packages/tailwindcss/src/index.test.ts

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4343,6 +4343,180 @@ describe('@custom-variant', () => {
43434343
}"
43444344
`)
43454345
})
4346+
4347+
test('@custom-variant can reuse existing @variant in the definition', async () => {
4348+
expect(
4349+
await compileCss(
4350+
css`
4351+
@custom-variant hocus {
4352+
@variant hover {
4353+
@variant focus {
4354+
@slot;
4355+
}
4356+
}
4357+
}
4358+
4359+
@tailwind utilities;
4360+
`,
4361+
['hocus:flex'],
4362+
),
4363+
).toMatchInlineSnapshot(`
4364+
"@media (hover: hover) {
4365+
.hocus\\:flex:hover:focus {
4366+
display: flex;
4367+
}
4368+
}"
4369+
`)
4370+
})
4371+
4372+
test('@custom-variant can reuse @custom-variant that is defined later', async () => {
4373+
expect(
4374+
await compileCss(
4375+
css`
4376+
@custom-variant hocus {
4377+
@variant custom-hover {
4378+
@variant focus {
4379+
@slot;
4380+
}
4381+
}
4382+
}
4383+
4384+
@custom-variant custom-hover (&:hover);
4385+
4386+
@tailwind utilities;
4387+
`,
4388+
['hocus:flex'],
4389+
),
4390+
).toMatchInlineSnapshot(`
4391+
".hocus\\:flex:hover:focus {
4392+
display: flex;
4393+
}"
4394+
`)
4395+
})
4396+
4397+
test('@custom-variant can reuse existing @variant that is overwritten later', async () => {
4398+
expect(
4399+
await compileCss(
4400+
css`
4401+
@custom-variant hocus {
4402+
@variant hover {
4403+
@variant focus {
4404+
@slot;
4405+
}
4406+
}
4407+
}
4408+
4409+
@custom-variant hover (&:hover);
4410+
4411+
@tailwind utilities;
4412+
`,
4413+
['hocus:flex'],
4414+
),
4415+
).toMatchInlineSnapshot(`
4416+
".hocus\\:flex:hover:focus {
4417+
display: flex;
4418+
}"
4419+
`)
4420+
})
4421+
4422+
test('@custom-variant cannot use @variant that eventually results in a circular dependency', async () => {
4423+
return expect(() =>
4424+
compileCss(
4425+
css`
4426+
@custom-variant custom-variant {
4427+
@variant foo {
4428+
@slot;
4429+
}
4430+
}
4431+
4432+
@custom-variant foo {
4433+
@variant hover {
4434+
@variant bar {
4435+
@slot;
4436+
}
4437+
}
4438+
}
4439+
4440+
@custom-variant bar {
4441+
@variant focus {
4442+
@variant baz {
4443+
@slot;
4444+
}
4445+
}
4446+
}
4447+
4448+
@custom-variant baz {
4449+
@variant active {
4450+
@variant foo {
4451+
@slot;
4452+
}
4453+
}
4454+
}
4455+
4456+
@tailwind utilities;
4457+
`,
4458+
['foo:flex'],
4459+
),
4460+
).rejects.toThrowErrorMatchingInlineSnapshot(`
4461+
[Error: Circular dependency detected in custom variants:
4462+
4463+
@custom-variant custom-variant {
4464+
@variant foo { … }
4465+
}
4466+
@custom-variant foo { /* ← */
4467+
@variant bar { … }
4468+
}
4469+
@custom-variant bar {
4470+
@variant baz { … }
4471+
}
4472+
@custom-variant baz {
4473+
@variant foo { … }
4474+
}
4475+
]
4476+
`)
4477+
})
4478+
4479+
test('@custom-variant setup that results in a circular dependency error can be solved', async () => {
4480+
expect(
4481+
await compileCss(
4482+
css`
4483+
@custom-variant foo {
4484+
@variant hover {
4485+
@variant bar {
4486+
@slot;
4487+
}
4488+
}
4489+
}
4490+
4491+
@custom-variant bar {
4492+
@variant focus {
4493+
@variant baz {
4494+
@slot;
4495+
}
4496+
}
4497+
}
4498+
4499+
@custom-variant baz {
4500+
@variant active {
4501+
@variant foo {
4502+
@slot;
4503+
}
4504+
}
4505+
}
4506+
4507+
/* Break the circle */
4508+
@custom-variant foo ([data-broken-circle] &);
4509+
4510+
@tailwind utilities;
4511+
`,
4512+
['baz:flex'],
4513+
),
4514+
).toMatchInlineSnapshot(`
4515+
"[data-broken-circle] .baz\\:flex:active {
4516+
display: flex;
4517+
}"
4518+
`)
4519+
})
43464520
})
43474521

43484522
describe('@utility', () => {

0 commit comments

Comments
 (0)