Skip to content

Commit ccc1ed5

Browse files
committed
Added more comprehensive tests for interleave and one that breaks additions in styled-components#52
1 parent 4706de2 commit ccc1ed5

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed

test/utils.test.js

+122
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,128 @@ describe('utils', () => {
3838
'\n display: block;\n color: $dummyValue;\n background: blue;\n'
3939
)
4040
})
41+
42+
it('converts interpolated expressions to dummy mixins', () => {
43+
const quasis = [
44+
{
45+
value: {
46+
raw: '\n display: block;\n '
47+
}
48+
},
49+
{
50+
value: {
51+
raw: '\n background: blue;\n'
52+
}
53+
}
54+
]
55+
const expressions = [
56+
{
57+
name: undefined
58+
}
59+
]
60+
expect(interleave(quasis, expressions)).toEqual(
61+
'\n display: block;\n -styled-mixin0: dummyValue;\n background: blue;\n'
62+
)
63+
})
64+
65+
it('correctly converts several interpolations within a single property', () => {
66+
const quasis = [
67+
{
68+
value: {
69+
raw: '\n display: block;\n border: '
70+
}
71+
},
72+
{
73+
value: {
74+
raw: ' '
75+
}
76+
},
77+
{
78+
value: {
79+
raw: ' '
80+
}
81+
},
82+
{
83+
value: {
84+
raw: ';\n background: blue;\n'
85+
}
86+
}
87+
]
88+
const expressions = [
89+
{
90+
name: 'borderWidth'
91+
},
92+
{
93+
name: 'borderStyle'
94+
},
95+
{
96+
name: 'color'
97+
}
98+
]
99+
expect(interleave(quasis, expressions)).toEqual(
100+
'\n display: block;\n border: $dummyValue $dummyValue $dummyValue;\n background: blue;\n'
101+
)
102+
})
103+
104+
it('correctly handles several interpolations in single line of css', () => {
105+
const quasis1 = [
106+
{
107+
value: {
108+
raw: '\n display: '
109+
}
110+
},
111+
{
112+
value: {
113+
raw: '; background: '
114+
}
115+
},
116+
{
117+
value: {
118+
raw: ';\n'
119+
}
120+
}
121+
]
122+
const expressions1 = [
123+
{
124+
name: 'display'
125+
},
126+
{
127+
name: 'background'
128+
}
129+
]
130+
expect(interleave(quasis1, expressions1)).toEqual(
131+
'\n display: $dummyValue; background: $dummyValue;\n'
132+
)
133+
134+
const quasis2 = [
135+
{
136+
value: {
137+
raw: '\n display: '
138+
}
139+
},
140+
{
141+
value: {
142+
raw: '; '
143+
}
144+
},
145+
{
146+
value: {
147+
raw: '\n'
148+
}
149+
}
150+
]
151+
const expressions2 = [
152+
{
153+
name: 'display'
154+
},
155+
{
156+
name: undefined
157+
}
158+
]
159+
expect(interleave(quasis2, expressions2)).toEqual(
160+
'\n display: $dummyValue; -styled-mixin0: dummyValue\n'
161+
)
162+
})
41163
})
42164

43165
describe('isLastLineWhitespaceOnly', () => {

0 commit comments

Comments
 (0)