Skip to content

Commit 3c44743

Browse files
committed
add tests for arbitrary variants
1 parent a473214 commit 3c44743

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

tests/arbitrary-variants.test.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { twMerge } from '../src'
2+
3+
test('basic arbitrary variants', () => {
4+
expect(twMerge('[&>*]:underline [&>*]:line-through')).toBe('[&>*]:line-through')
5+
expect(twMerge('[&>*]:underline [&>*]:line-through [&_div]:line-through')).toBe(
6+
'[&>*]:line-through [&_div]:line-through'
7+
)
8+
})
9+
10+
test('arbitrary variants with modifiers', () => {
11+
expect(twMerge('dark:lg:hover:[&>*]:underline dark:lg:hover:[&>*]:line-through')).toBe(
12+
'dark:lg:hover:[&>*]:line-through'
13+
)
14+
expect(twMerge('dark:lg:hover:[&>*]:underline dark:hover:lg:[&>*]:line-through')).toBe(
15+
'dark:hover:lg:[&>*]:line-through'
16+
)
17+
// Whether a modifier is before or after arbitrary variant matters
18+
expect(twMerge('hover:[&>*]:underline [&>*]:hover:line-through')).toBe(
19+
'hover:[&>*]:underline [&>*]:hover:line-through'
20+
)
21+
expect(
22+
twMerge(
23+
'hover:dark:[&>*]:underline dark:hover:[&>*]:underline dark:[&>*]:hover:line-through'
24+
)
25+
).toBe('dark:hover:[&>*]:underline dark:[&>*]:hover:line-through')
26+
})
27+
28+
test('arbitrary variants with complex syntax in them', () => {
29+
expect(
30+
twMerge(
31+
'[@media_screen{@media(hover:hover)}]:underline [@media_screen{@media(hover:hover)}]:line-through'
32+
)
33+
).toBe('[@media_screen{@media(hover:hover)}]:line-through')
34+
expect(
35+
twMerge(
36+
'hover:[@media_screen{@media(hover:hover)}]:underline hover:[@media_screen{@media(hover:hover)}]:line-through'
37+
)
38+
).toBe('hover:[@media_screen{@media(hover:hover)}]:line-through')
39+
})
40+
41+
test('arbitrary variants with attribute selectors', () => {
42+
expect(twMerge('[&[data-open]]:underline [&[data-open]]:line-through')).toBe(
43+
'[&[data-open]]:line-through'
44+
)
45+
})
46+
47+
test('arbitrary variants with multiple attribute selectors', () => {
48+
expect(
49+
twMerge(
50+
'[&[data-foo][data-bar]:not([data-baz])]:underline [&[data-foo][data-bar]:not([data-baz])]:line-through'
51+
)
52+
).toBe('[&[data-foo][data-bar]:not([data-baz])]:line-through')
53+
})
54+
55+
test('multiple arbitrary variants', () => {
56+
expect(twMerge('[&>*]:[&_div]:underline [&>*]:[&_div]:line-through')).toBe(
57+
'[&>*]:[&_div]:line-through'
58+
)
59+
expect(twMerge('[&>*]:[&_div]:underline [&_div]:[&>*]:line-through')).toBe(
60+
'[&>*]:[&_div]:underline [&_div]:[&>*]:line-through'
61+
)
62+
expect(
63+
twMerge(
64+
'hover:dark:[&>*]:focus:disabled:[&_div]:underline dark:hover:[&>*]:disabled:focus:[&_div]:line-through'
65+
)
66+
).toBe('dark:hover:[&>*]:disabled:focus:[&_div]:line-through')
67+
expect(
68+
twMerge(
69+
'hover:dark:[&>*]:focus:[&_div]:disabled:underline dark:hover:[&>*]:disabled:focus:[&_div]:line-through'
70+
)
71+
).toBe(
72+
'hover:dark:[&>*]:focus:[&_div]:disabled:underline dark:hover:[&>*]:disabled:focus:[&_div]:line-through'
73+
)
74+
})

0 commit comments

Comments
 (0)