Skip to content

Commit 98f97cd

Browse files
committed
test: update tests
1 parent a2e23ea commit 98f97cd

File tree

2 files changed

+71
-3
lines changed

2 files changed

+71
-3
lines changed

test/TailwindConverter.spec.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const simpleCSS = `
1515
padding-bottom: 12px;
1616
font-size: 12px;
1717
animation-delay: 200ms;
18+
border-right: 2px dashed;
19+
border: 4px solid transparent;
1820
1921
&:hover {
2022
filter: blur(4px) brightness(0.5) sepia(100%) contrast(1) hue-rotate(30deg)
@@ -74,6 +76,11 @@ describe('TailwindConverter', () => {
7476
tailwindClasses: [
7577
'text-xs',
7678
'py-3',
79+
'border-r-2',
80+
'border-dashed',
81+
'border-4',
82+
'border-solid',
83+
'border-transparent',
7784
'hover:blur-sm',
7885
'hover:brightness-50',
7986
'hover:sepia',
@@ -97,6 +104,7 @@ describe('TailwindConverter', () => {
97104
separator: '_',
98105
corePlugins: {
99106
fontWeight: false,
107+
borderColor: false,
100108
},
101109
},
102110
});
@@ -109,6 +117,8 @@ describe('TailwindConverter', () => {
109117
tailwindClasses: [
110118
'tw-text-xs',
111119
'tw-py-3',
120+
'tw-border-r-2',
121+
'tw-border-dashed',
112122
'hover_tw-blur-sm',
113123
'hover_tw-brightness-50',
114124
'hover_tw-sepia',
@@ -126,6 +136,12 @@ describe('TailwindConverter', () => {
126136
it('should convert unconvertible declarations if `arbitraryPropertiesIsEnabled` config is enabled', async () => {
127137
const converter = createTailwindConverter({
128138
arbitraryPropertiesIsEnabled: true,
139+
tailwindConfig: {
140+
content: [],
141+
corePlugins: {
142+
borderColor: false,
143+
},
144+
},
129145
});
130146
const converted = await converter.convertCSS(simpleCSS);
131147

@@ -136,7 +152,10 @@ describe('TailwindConverter', () => {
136152
tailwindClasses: [
137153
'text-xs',
138154
'[animation-delay:200ms]',
155+
'[border:4px_solid_transparent]',
139156
'py-3',
157+
'border-r-2',
158+
'border-dashed',
140159
'hover:blur-sm',
141160
'hover:brightness-50',
142161
'hover:sepia',
@@ -153,6 +172,47 @@ describe('TailwindConverter', () => {
153172
]);
154173
});
155174

175+
it('should not prefix arbitrary properties', async () => {
176+
const converter = createTailwindConverter({
177+
arbitraryPropertiesIsEnabled: true,
178+
tailwindConfig: {
179+
content: [],
180+
prefix: 'tw-',
181+
separator: '_',
182+
corePlugins: {
183+
borderColor: false,
184+
},
185+
},
186+
});
187+
const converted = await converter.convertCSS(simpleCSS);
188+
189+
expect(converted.convertedRoot.toString()).toMatchSnapshot();
190+
expect(converted.nodes).toEqual([
191+
{
192+
rule: expect.objectContaining({ selector: '.foo' }),
193+
tailwindClasses: [
194+
'tw-text-xs',
195+
'[animation-delay:200ms]',
196+
'[border:4px_solid_transparent]',
197+
'tw-py-3',
198+
'tw-border-r-2',
199+
'tw-border-dashed',
200+
'hover_tw-blur-sm',
201+
'hover_tw-brightness-50',
202+
'hover_tw-sepia',
203+
'hover_tw-contrast-100',
204+
'hover_tw-hue-rotate-30',
205+
'hover_tw-invert-0',
206+
'hover_tw-opacity-5',
207+
'hover_tw-saturate-150',
208+
'hover_[transform:translateX(12px)_translateY(0.5em)_translateZ(0.5rem)_scaleY(0.725)_rotate(124deg)]',
209+
'hover_tw-text-base',
210+
'md_tw-font-semibold',
211+
],
212+
},
213+
]);
214+
});
215+
156216
it('should return an empty result when converting an empty string', async () => {
157217
const converter = createTailwindConverter();
158218
const converted = await converter.convertCSS('');

test/__snapshots__/TailwindConverter.spec.ts.snap

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
exports[`TailwindConverter should consider \`prefix\`, \`separator\` and \`corePlugins\` configurations 1`] = `
44
".foo {
5-
@apply tw-text-xs tw-py-3 hover_tw-blur-sm hover_tw-brightness-50 hover_tw-sepia hover_tw-contrast-100 hover_tw-hue-rotate-30 hover_tw-invert-0 hover_tw-opacity-5 hover_tw-saturate-150 hover_tw-text-base;
5+
@apply tw-text-xs tw-py-3 tw-border-r-2 tw-border-dashed hover_tw-blur-sm hover_tw-brightness-50 hover_tw-sepia hover_tw-contrast-100 hover_tw-hue-rotate-30 hover_tw-invert-0 hover_tw-opacity-5 hover_tw-saturate-150 hover_tw-text-base;
66
animation-delay: 200ms;
7+
border: 4px solid transparent;
78
}
89
.foo:hover {
910
transform: translateX(12px) translateY(0.5em) translateZ(0.5rem)
@@ -154,7 +155,7 @@ exports[`TailwindConverter should convert the css part string 1`] = `
154155

155156
exports[`TailwindConverter should convert the simple CSS 1`] = `
156157
".foo {
157-
@apply text-xs py-3 hover:blur-sm hover:brightness-50 hover:sepia hover:contrast-100 hover:hue-rotate-30 hover:invert-0 hover:opacity-5 hover:saturate-150 hover:text-base md:font-semibold;
158+
@apply text-xs py-3 border-r-2 border-dashed border-4 border-solid border-transparent hover:blur-sm hover:brightness-50 hover:sepia hover:contrast-100 hover:hue-rotate-30 hover:invert-0 hover:opacity-5 hover:saturate-150 hover:text-base md:font-semibold;
158159
animation-delay: 200ms;
159160
}
160161
.foo:hover {
@@ -166,7 +167,14 @@ exports[`TailwindConverter should convert the simple CSS 1`] = `
166167

167168
exports[`TailwindConverter should convert unconvertible declarations if \`arbitraryPropertiesIsEnabled\` config is enabled 1`] = `
168169
".foo {
169-
@apply text-xs [animation-delay:200ms] py-3 hover:blur-sm hover:brightness-50 hover:sepia hover:contrast-100 hover:hue-rotate-30 hover:invert-0 hover:opacity-5 hover:saturate-150 hover:[transform:translateX(12px)_translateY(0.5em)_translateZ(0.5rem)_scaleY(0.725)_rotate(124deg)] hover:text-base md:font-semibold;
170+
@apply text-xs [animation-delay:200ms] [border:4px_solid_transparent] py-3 border-r-2 border-dashed hover:blur-sm hover:brightness-50 hover:sepia hover:contrast-100 hover:hue-rotate-30 hover:invert-0 hover:opacity-5 hover:saturate-150 hover:[transform:translateX(12px)_translateY(0.5em)_translateZ(0.5rem)_scaleY(0.725)_rotate(124deg)] hover:text-base md:font-semibold;
171+
}
172+
"
173+
`;
174+
175+
exports[`TailwindConverter should not prefix arbitrary properties 1`] = `
176+
".foo {
177+
@apply tw-text-xs [animation-delay:200ms] [border:4px_solid_transparent] tw-py-3 tw-border-r-2 tw-border-dashed hover_tw-blur-sm hover_tw-brightness-50 hover_tw-sepia hover_tw-contrast-100 hover_tw-hue-rotate-30 hover_tw-invert-0 hover_tw-opacity-5 hover_tw-saturate-150 hover_[transform:translateX(12px)_translateY(0.5em)_translateZ(0.5rem)_scaleY(0.725)_rotate(124deg)] hover_tw-text-base md_tw-font-semibold;
170178
}
171179
"
172180
`;

0 commit comments

Comments
 (0)