Skip to content

Commit 622c191

Browse files
authored
fix(prefer-to-have-style): handle toHaveProperty with variable property name (#347)
1 parent 93bda4a commit 622c191

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/__tests__/lib/rules/prefer-to-have-style.js

+28
Original file line numberDiff line numberDiff line change
@@ -177,5 +177,33 @@ ruleTester.run("prefer-to-have-style", rule, {
177177
errors,
178178
output: null,
179179
},
180+
{
181+
code: `
182+
expect(myStencil({color: '--my-var'}).style).toHaveProperty(
183+
myStencil.vars.color,
184+
'var(--my-var)'
185+
);
186+
`,
187+
errors,
188+
output: `
189+
expect(myStencil({color: '--my-var'})).toHaveStyle(
190+
{[myStencil.vars.color]: 'var(--my-var)'}
191+
);
192+
`,
193+
},
194+
{
195+
code: `
196+
expect(myStencil({color: '--my-var'}).style).not.toHaveProperty(
197+
myStencil.vars.color,
198+
'var(--my-var)'
199+
);
200+
`,
201+
errors,
202+
output: `
203+
expect(myStencil({color: '--my-var'})).not.toHaveStyle(
204+
{[myStencil.vars.color]: 'var(--my-var)'}
205+
);
206+
`,
207+
},
180208
],
181209
});

src/rules/prefer-to-have-style.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ export const create = (context) => {
256256
fixer.replaceText(matcher, "toHaveStyle"),
257257
fixer.replaceTextRange(
258258
[styleName.range[0], styleValue.range[1]],
259-
`{${camelCase(styleName.value)}: ${context
259+
`{${getReplacementObjectProperty(styleName)}: ${context
260260
.getSourceCode()
261261
.getText(styleValue)}}`
262262
),
@@ -288,7 +288,7 @@ export const create = (context) => {
288288
fixer.replaceText(matcher, "toHaveStyle"),
289289
fixer.replaceTextRange(
290290
[styleName.range[0], styleValue.range[1]],
291-
`{${camelCase(styleName.value)}: ${context
291+
`{${getReplacementObjectProperty(styleName)}: ${context
292292
.getSourceCode()
293293
.getText(styleValue)}}`
294294
),

0 commit comments

Comments
 (0)