Skip to content

Commit

Permalink
fix(prefer-to-have-style): handle toHaveProperty with variable prop…
Browse files Browse the repository at this point in the history
…erty name (#347)
  • Loading branch information
G-Rath committed Mar 21, 2024
1 parent 93bda4a commit 622c191
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
28 changes: 28 additions & 0 deletions src/__tests__/lib/rules/prefer-to-have-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,33 @@ ruleTester.run("prefer-to-have-style", rule, {
errors,
output: null,
},
{
code: `
expect(myStencil({color: '--my-var'}).style).toHaveProperty(
myStencil.vars.color,
'var(--my-var)'
);
`,
errors,
output: `
expect(myStencil({color: '--my-var'})).toHaveStyle(
{[myStencil.vars.color]: 'var(--my-var)'}
);
`,
},
{
code: `
expect(myStencil({color: '--my-var'}).style).not.toHaveProperty(
myStencil.vars.color,
'var(--my-var)'
);
`,
errors,
output: `
expect(myStencil({color: '--my-var'})).not.toHaveStyle(
{[myStencil.vars.color]: 'var(--my-var)'}
);
`,
},
],
});
4 changes: 2 additions & 2 deletions src/rules/prefer-to-have-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ export const create = (context) => {
fixer.replaceText(matcher, "toHaveStyle"),
fixer.replaceTextRange(
[styleName.range[0], styleValue.range[1]],
`{${camelCase(styleName.value)}: ${context
`{${getReplacementObjectProperty(styleName)}: ${context
.getSourceCode()
.getText(styleValue)}}`
),
Expand Down Expand Up @@ -288,7 +288,7 @@ export const create = (context) => {
fixer.replaceText(matcher, "toHaveStyle"),
fixer.replaceTextRange(
[styleName.range[0], styleValue.range[1]],
`{${camelCase(styleName.value)}: ${context
`{${getReplacementObjectProperty(styleName)}: ${context
.getSourceCode()
.getText(styleValue)}}`
),
Expand Down

0 comments on commit 622c191

Please sign in to comment.