Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eslint-plugin-jest-dom

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-jest-dom - npm Package Compare versions

Comparing version 1.2.0 to 1.2.1

33

lib/createBannedAttributeRule.js

@@ -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

2

package.json
{
"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)`,

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc