Skip to content

Commit f799577

Browse files
committed
use data-test: instead of hover:
This allows us to just change the data attribute when making a change instead of relying on `hover:`. In this PR `hover:` will use `@media (hover: hover)` which is not implemented in Firefox on Linux at the time of writing this PR.
1 parent 04f6b8b commit f799577

File tree

1 file changed

+56
-51
lines changed

1 file changed

+56
-51
lines changed

packages/tailwindcss/tests/ui.spec.ts

Lines changed: 56 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ const css = String.raw
1111
test('touch action', async ({ page }) => {
1212
let { getPropertyValue } = await render(
1313
page,
14-
html`<div id="x" class="touch-pan-x touch-pan-y hover:touch-pinch-zoom">Hello world</div>`,
14+
html`<div id="x" class="touch-pan-x touch-pan-y data-test:touch-pinch-zoom">Hello world</div>`,
1515
)
1616

1717
expect(await getPropertyValue('#x', 'touch-action')).toEqual('pan-x pan-y')
1818

19-
await page.locator('#x').hover()
19+
await page.locator('#x').evaluate((el) => (el.dataset.test = ''))
2020

2121
expect([
2222
// `manipulation` is an alias for `pan-x pan-y pinch-zoom` and some engines
@@ -71,7 +71,7 @@ test('background gradient, going from 2 to 3', async ({ page }) => {
7171
let { getPropertyValue } = await render(
7272
page,
7373
html`
74-
<div id="x" class="bg-gradient-to-r from-red-500 hover:via-green-500 to-blue-500">
74+
<div id="x" class="bg-gradient-to-r from-red-500 data-test:via-green-500 to-blue-500">
7575
Hello world
7676
</div>
7777
`,
@@ -81,7 +81,7 @@ test('background gradient, going from 2 to 3', async ({ page }) => {
8181
'linear-gradient(to right, rgb(239, 68, 68) 0%, rgb(59, 130, 246) 100%)',
8282
)
8383

84-
await page.locator('#x').hover()
84+
await page.locator('#x').evaluate((el) => (el.dataset.test = ''))
8585

8686
expect(await getPropertyValue('#x', 'background-image')).toEqual(
8787
'linear-gradient(to right, rgb(239, 68, 68) 0%, rgb(34, 197, 94) 50%, rgb(59, 130, 246) 100%)',
@@ -92,7 +92,10 @@ test('background gradient, going from 3 to 2', async ({ page }) => {
9292
let { getPropertyValue } = await render(
9393
page,
9494
html`
95-
<div id="x" class="bg-gradient-to-r from-red-500 via-green-500 hover:via-none to-blue-500">
95+
<div
96+
id="x"
97+
class="bg-gradient-to-r from-red-500 via-green-500 data-test:via-none to-blue-500"
98+
>
9699
Hello world
97100
</div>
98101
`,
@@ -102,7 +105,7 @@ test('background gradient, going from 3 to 2', async ({ page }) => {
102105
'linear-gradient(to right, rgb(239, 68, 68) 0%, rgb(34, 197, 94) 50%, rgb(59, 130, 246) 100%)',
103106
)
104107

105-
await page.locator('#x').hover()
108+
await page.locator('#x').evaluate((el) => (el.dataset.test = ''))
106109

107110
expect(await getPropertyValue('#x', 'background-image')).toEqual(
108111
'linear-gradient(to right, rgb(239, 68, 68) 0%, rgb(59, 130, 246) 100%)',
@@ -223,8 +226,8 @@ test('shadow colors', async ({ page }) => {
223226
<div id="a" class="shadow shadow-red-500"></div>
224227
<div id="b" class="shadow-xl shadow-red-500"></div>
225228
<div id="c" class="shadow-[0px_2px_4px] shadow-red-500"></div>
226-
<div id="d" class="shadow shadow-red-500 hover:shadow-xl">Hello world</div>
227-
<div id="e" class="shadow shadow-red-500 hover:shadow-xl hover:shadow-initial">
229+
<div id="d" class="shadow shadow-red-500 data-test:shadow-xl">Hello world</div>
230+
<div id="e" class="shadow shadow-red-500 data-test:shadow-xl data-test:shadow-initial">
228231
Hello world
229232
</div>
230233
`,
@@ -268,7 +271,7 @@ test('shadow colors', async ({ page }) => {
268271
].join(', '),
269272
)
270273

271-
await page.locator('#d').hover()
274+
await page.locator('#d').evaluate((el) => (el.dataset.test = ''))
272275

273276
expect(await getPropertyValue('#d', 'box-shadow')).toEqual(
274277
[
@@ -290,7 +293,7 @@ test('shadow colors', async ({ page }) => {
290293
].join(', '),
291294
)
292295

293-
await page.locator('#e').hover()
296+
await page.locator('#e').evaluate((el) => (el.dataset.test = ''))
294297

295298
expect(await getPropertyValue('#e', 'box-shadow')).toEqual(
296299
[
@@ -310,10 +313,12 @@ test('inset shadow colors', async ({ page }) => {
310313
<div id="a" class="inset-shadow-sm inset-shadow-red-500"></div>
311314
<div id="b" class="inset-shadow inset-shadow-red-500"></div>
312315
<div id="c" class="inset-shadow-[0px_3px_6px] inset-shadow-red-500"></div>
313-
<div id="d" class="inset-shadow-sm inset-shadow-red-500 hover:inset-shadow">Hello world</div>
316+
<div id="d" class="inset-shadow-sm inset-shadow-red-500 data-test:inset-shadow">
317+
Hello world
318+
</div>
314319
<div
315320
id="e"
316-
class="inset-shadow-sm inset-shadow-red-500 hover:inset-shadow hover:inset-shadow-initial"
321+
class="inset-shadow-sm inset-shadow-red-500 data-test:inset-shadow data-test:inset-shadow-initial"
317322
>
318323
Hello world
319324
</div>
@@ -358,7 +363,7 @@ test('inset shadow colors', async ({ page }) => {
358363
].join(', '),
359364
)
360365

361-
await page.locator('#d').hover()
366+
await page.locator('#d').evaluate((el) => (el.dataset.test = ''))
362367

363368
expect(await getPropertyValue('#d', 'box-shadow')).toEqual(
364369
[
@@ -380,7 +385,7 @@ test('inset shadow colors', async ({ page }) => {
380385
].join(', '),
381386
)
382387

383-
await page.locator('#e').hover()
388+
await page.locator('#e').evaluate((el) => (el.dataset.test = ''))
384389

385390
expect(await getPropertyValue('#e', 'box-shadow')).toEqual(
386391
[
@@ -405,14 +410,14 @@ test('outline style is optional', async ({ page }) => {
405410
test('outline style is preserved when changing outline width', async ({ page }) => {
406411
let { getPropertyValue } = await render(
407412
page,
408-
html`<div id="x" class="outline-2 outline-dotted outline-white hover:outline-4">
413+
html`<div id="x" class="outline-2 outline-dotted outline-white data-test:outline-4">
409414
Hello world
410415
</div>`,
411416
)
412417

413418
expect(await getPropertyValue('#x', 'outline')).toEqual('rgb(255, 255, 255) dotted 2px')
414419

415-
await page.locator('#x').hover()
420+
await page.locator('#x').evaluate((el) => (el.dataset.test = ''))
416421

417422
expect(await getPropertyValue('#x', 'outline')).toEqual('rgb(255, 255, 255) dotted 4px')
418423
})
@@ -429,40 +434,40 @@ test('borders can be added without a border-style utility', async ({ page }) =>
429434
test('borders can be added to a single side without a border-style utility', async ({ page }) => {
430435
let { getPropertyValue } = await render(
431436
page,
432-
html`<div id="x" class="text-black border-r-2 border-dashed hover:border-r-4">
437+
html`<div id="x" class="text-black border-r-2 border-dashed data-test:border-r-4">
433438
Hello world
434439
</div>`,
435440
)
436441
expect(await getPropertyValue('#x', 'border-right')).toEqual('2px dashed rgb(0, 0, 0)')
437442

438-
await page.locator('#x').hover()
443+
await page.locator('#x').evaluate((el) => (el.dataset.test = ''))
439444

440445
expect(await getPropertyValue('#x', 'border-right')).toEqual('4px dashed rgb(0, 0, 0)')
441446
})
442447

443448
test('dividers can be added without setting border-style', async ({ page }) => {
444449
let { getPropertyValue } = await render(
445450
page,
446-
html`<div id="a" class="divide-y-2 divide-dashed hover:divide-y-4">
451+
html`<div id="a" class="divide-y-2 divide-dashed data-test:divide-y-4">
447452
<div id="b">First</div>
448453
<div>Second</div>
449454
</div>`,
450455
)
451456
expect(await getPropertyValue('#b', 'border-bottom')).toEqual('2px dashed rgb(0, 0, 0)')
452457

453-
await page.locator('#a').hover()
458+
await page.locator('#a').evaluate((el) => (el.dataset.test = ''))
454459

455460
expect(await getPropertyValue('#b', 'border-bottom')).toEqual('4px dashed rgb(0, 0, 0)')
456461
})
457462

458463
test('scale can be a number or percentage', async ({ page }) => {
459464
let { getPropertyValue } = await render(
460465
page,
461-
html`<div id="x" class="scale-[50%] hover:scale-[1.5]">Hello world</div>`,
466+
html`<div id="x" class="scale-[50%] data-test:scale-[1.5]">Hello world</div>`,
462467
)
463468
expect(await getPropertyValue('#x', 'scale')).toEqual('0.5')
464469

465-
await page.locator('#x').hover()
470+
await page.locator('#x').evaluate((el) => (el.dataset.test = ''))
466471

467472
expect(await getPropertyValue('#x', 'scale')).toEqual('1.5')
468473
})
@@ -471,12 +476,12 @@ test('scale can be a number or percentage', async ({ page }) => {
471476
test('content-none persists when conditionally styling a pseudo-element', async ({ page }) => {
472477
let { getPropertyValue } = await render(
473478
page,
474-
html`<div id="x" class="after:content-none after:hover:underline">Hello world</div>`,
479+
html`<div id="x" class="after:content-none after:data-test:underline">Hello world</div>`,
475480
)
476481

477482
expect(await getPropertyValue(['#x', '::after'], 'content')).toEqual('none')
478483

479-
await page.locator('#x').hover()
484+
await page.locator('#x').evaluate((el) => (el.dataset.test = ''))
480485

481486
expect(await getPropertyValue(['#x', '::after'], 'content')).toEqual('none')
482487
})
@@ -485,9 +490,9 @@ test('explicit leading utilities are respected when overriding font-size', async
485490
let { getPropertyValue } = await render(
486491
page,
487492
html`
488-
<div id="x" class="text-sm hover:text-xl">Hello world</div>
489-
<div id="y" class="text-sm leading-tight hover:text-xl">Hello world</div>
490-
<div id="z" class="text-sm leading-[10px] hover:text-xl">Hello world</div>
493+
<div id="x" class="text-sm data-test:text-xl">Hello world</div>
494+
<div id="y" class="text-sm leading-tight data-test:text-xl">Hello world</div>
495+
<div id="z" class="text-sm leading-[10px] data-test:text-xl">Hello world</div>
491496
`,
492497
css`
493498
@theme {
@@ -501,25 +506,25 @@ test('explicit leading utilities are respected when overriding font-size', async
501506
)
502507

503508
expect(await getPropertyValue('#x', 'line-height')).toEqual('16px')
504-
await page.locator('#x').hover()
509+
await page.locator('#x').evaluate((el) => (el.dataset.test = ''))
505510
expect(await getPropertyValue('#x', 'line-height')).toEqual('24px')
506511

507512
expect(await getPropertyValue('#y', 'line-height')).toEqual('8px')
508-
await page.locator('#y').hover()
513+
await page.locator('#y').evaluate((el) => (el.dataset.test = ''))
509514
expect(await getPropertyValue('#y', 'line-height')).toEqual('8px')
510515

511516
expect(await getPropertyValue('#z', 'line-height')).toEqual('10px')
512-
await page.locator('#z').hover()
517+
await page.locator('#z').evaluate((el) => (el.dataset.test = ''))
513518
expect(await getPropertyValue('#z', 'line-height')).toEqual('10px')
514519
})
515520

516521
test('explicit leading utilities are overridden by line-height modifiers', async ({ page }) => {
517522
let { getPropertyValue } = await render(
518523
page,
519524
html`
520-
<div id="x" class="text-sm hover:text-xl/[100px]">Hello world</div>
521-
<div id="y" class="text-sm leading-tight hover:text-xl/[100px]">Hello world</div>
522-
<div id="z" class="text-sm leading-[10px] hover:text-xl/[100px]">Hello world</div>
525+
<div id="x" class="text-sm data-test:text-xl/[100px]">Hello world</div>
526+
<div id="y" class="text-sm leading-tight data-test:text-xl/[100px]">Hello world</div>
527+
<div id="z" class="text-sm leading-[10px] data-test:text-xl/[100px]">Hello world</div>
523528
`,
524529
css`
525530
@theme {
@@ -533,25 +538,25 @@ test('explicit leading utilities are overridden by line-height modifiers', async
533538
)
534539

535540
expect(await getPropertyValue('#x', 'line-height')).toEqual('16px')
536-
await page.locator('#x').hover()
541+
await page.locator('#x').evaluate((el) => (el.dataset.test = ''))
537542
expect(await getPropertyValue('#x', 'line-height')).toEqual('100px')
538543

539544
expect(await getPropertyValue('#y', 'line-height')).toEqual('8px')
540-
await page.locator('#y').hover()
545+
await page.locator('#y').evaluate((el) => (el.dataset.test = ''))
541546
expect(await getPropertyValue('#y', 'line-height')).toEqual('100px')
542547

543548
expect(await getPropertyValue('#z', 'line-height')).toEqual('10px')
544-
await page.locator('#z').hover()
549+
await page.locator('#z').evaluate((el) => (el.dataset.test = ''))
545550
expect(await getPropertyValue('#z', 'line-height')).toEqual('100px')
546551
})
547552

548553
test('explicit tracking utilities are respected when overriding font-size', async ({ page }) => {
549554
let { getPropertyValue } = await render(
550555
page,
551556
html`
552-
<div id="x" class="text-sm hover:text-xl">Hello world</div>
553-
<div id="y" class="text-sm tracking-tight hover:text-xl">Hello world</div>
554-
<div id="z" class="text-sm tracking-[3px] hover:text-xl">Hello world</div>
557+
<div id="x" class="text-sm data-test:text-xl">Hello world</div>
558+
<div id="y" class="text-sm tracking-tight data-test:text-xl">Hello world</div>
559+
<div id="z" class="text-sm tracking-[3px] data-test:text-xl">Hello world</div>
555560
`,
556561
css`
557562
@theme {
@@ -563,25 +568,25 @@ test('explicit tracking utilities are respected when overriding font-size', asyn
563568
)
564569

565570
expect(await getPropertyValue('#x', 'letter-spacing')).toEqual('5px')
566-
await page.locator('#x').hover()
571+
await page.locator('#x').evaluate((el) => (el.dataset.test = ''))
567572
expect(await getPropertyValue('#x', 'letter-spacing')).toEqual('10px')
568573

569574
expect(await getPropertyValue('#y', 'letter-spacing')).toEqual('1px')
570-
await page.locator('#y').hover()
575+
await page.locator('#y').evaluate((el) => (el.dataset.test = ''))
571576
expect(await getPropertyValue('#y', 'letter-spacing')).toEqual('1px')
572577

573578
expect(await getPropertyValue('#z', 'letter-spacing')).toEqual('3px')
574-
await page.locator('#z').hover()
579+
await page.locator('#z').evaluate((el) => (el.dataset.test = ''))
575580
expect(await getPropertyValue('#z', 'letter-spacing')).toEqual('3px')
576581
})
577582

578583
test('explicit font-weight utilities are respected when overriding font-size', async ({ page }) => {
579584
let { getPropertyValue } = await render(
580585
page,
581586
html`
582-
<div id="x" class="text-sm hover:text-xl">Hello world</div>
583-
<div id="y" class="text-sm font-bold hover:text-xl">Hello world</div>
584-
<div id="z" class="text-sm font-[900] hover:text-xl">Hello world</div>
587+
<div id="x" class="text-sm data-test:text-xl">Hello world</div>
588+
<div id="y" class="text-sm font-bold data-test:text-xl">Hello world</div>
589+
<div id="z" class="text-sm font-[900] data-test:text-xl">Hello world</div>
585590
`,
586591
css`
587592
@theme {
@@ -592,15 +597,15 @@ test('explicit font-weight utilities are respected when overriding font-size', a
592597
)
593598

594599
expect(await getPropertyValue('#x', 'font-weight')).toEqual('100')
595-
await page.locator('#x').hover()
600+
await page.locator('#x').evaluate((el) => (el.dataset.test = ''))
596601
expect(await getPropertyValue('#x', 'font-weight')).toEqual('200')
597602

598603
expect(await getPropertyValue('#y', 'font-weight')).toEqual('700')
599-
await page.locator('#y').hover()
604+
await page.locator('#y').evaluate((el) => (el.dataset.test = ''))
600605
expect(await getPropertyValue('#y', 'font-weight')).toEqual('700')
601606

602607
expect(await getPropertyValue('#z', 'font-weight')).toEqual('900')
603-
await page.locator('#z').hover()
608+
await page.locator('#z').evaluate((el) => (el.dataset.test = ''))
604609
expect(await getPropertyValue('#z', 'font-weight')).toEqual('900')
605610
})
606611

@@ -612,7 +617,7 @@ test('explicit duration and ease utilities are respected when overriding transit
612617
html`
613618
<div
614619
id="x"
615-
class="ease-[linear] duration-500 transition-[opacity] hover:transition-[background-color]"
620+
class="ease-[linear] duration-500 transition-[opacity] data-test:transition-[background-color]"
616621
>
617622
Hello world
618623
</div>
@@ -621,7 +626,7 @@ test('explicit duration and ease utilities are respected when overriding transit
621626

622627
expect(await getPropertyValue('#x', 'transition-timing-function')).toEqual('linear')
623628
expect(await getPropertyValue('#x', 'transition-duration')).toEqual('0.5s')
624-
await page.locator('#x').hover()
629+
await page.locator('#x').evaluate((el) => (el.dataset.test = ''))
625630
expect(await getPropertyValue('#x', 'transition-timing-function')).toEqual('linear')
626631
expect(await getPropertyValue('#x', 'transition-duration')).toEqual('0.5s')
627632
})
@@ -663,7 +668,7 @@ async function render(page: Page, content: string, extraCss: string = '') {
663668
content: optimizeCss(build(candidates)),
664669
})
665670

666-
await page.locator('#mouse-park').hover()
671+
await page.locator('#mouse-park').evaluate((el) => (el.dataset.test = ''))
667672

668673
return {
669674
getPropertyValue(selector: string | [string, string], property: string) {

0 commit comments

Comments
 (0)