eslint-plugin-jest-dom
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -35,2 +35,35 @@ module.exports = ({ preferred, negatedPreferred, attributes }) => context => { | ||
}, | ||
"CallExpression[callee.property.name=/toBe(Truthy|Falsy)?|toEqual/][callee.object.callee.name='expect']"( | ||
node | ||
) { | ||
const { | ||
arguments: [{ property, property: { name } = {} }], | ||
} = node.callee.object; | ||
const matcher = node.callee.property.name; | ||
const matcherArg = node.arguments.length && node.arguments[0].value; | ||
if (attributes.some(attr => attr === name)) { | ||
const isNegated = | ||
matcher.endsWith('Falsy') || | ||
((matcher === 'toBe' || matcher === 'toEqual') && | ||
matcherArg !== true); | ||
const correctFunction = getCorrectFunctionFor( | ||
node.callee.object, | ||
isNegated | ||
); | ||
context.report({ | ||
node, | ||
message: `Use ${correctFunction}() instead of checking .${name} directly`, | ||
fix(fixer) { | ||
return [ | ||
fixer.removeRange([property.start - 1, property.end]), | ||
fixer.replaceTextRange( | ||
[node.callee.property.start, node.end], | ||
`${correctFunction}()` | ||
), | ||
]; | ||
}, | ||
}); | ||
} | ||
}, | ||
"CallExpression[callee.property.name=/toHaveProperty|toHaveAttribute/][callee.object.property.name='not'][callee.object.object.callee.name='expect']"( | ||
@@ -37,0 +70,0 @@ node |
{ | ||
"name": "eslint-plugin-jest-dom", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "lint rules for use with jest-dom", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -25,2 +25,34 @@ module.exports = ({ preferred, negatedPreferred, attribute }) => { | ||
} | ||
let directChecks = []; | ||
if (!/-/.test(attribute)) { | ||
directChecks = [ | ||
{ | ||
code: `expect(getByText('foo').${attribute}).toBeTruthy()`, | ||
errors: [ | ||
{ | ||
message: `Use ${preferred} instead of checking .${attribute} directly`, | ||
}, | ||
], | ||
output: `expect(getByText('foo')).${[preferred]}`, | ||
}, | ||
{ | ||
code: `expect(getByText('foo').${attribute}).toBeFalsy()`, | ||
errors: [ | ||
{ | ||
message: `Use ${negatedPreferred} instead of checking .${attribute} directly`, | ||
}, | ||
], | ||
output: `expect(getByText('foo')).${[negatedPreferred]}`, | ||
}, | ||
{ | ||
code: `expect(getByText('foo').${attribute}).toBe(true)`, | ||
errors: [ | ||
{ | ||
message: `Use ${preferred} instead of checking .${attribute} directly`, | ||
}, | ||
], | ||
output: `expect(getByText('foo')).${[preferred]}`, | ||
}, | ||
]; | ||
} | ||
return { | ||
@@ -35,2 +67,3 @@ valid: [ | ||
...doubleNegativeCases, | ||
...directChecks, | ||
{ | ||
@@ -37,0 +70,0 @@ code: `expect(element).toHaveProperty('${attribute}', true)`, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43744
861