eslint-plugin-jest-dom
Advanced tools
Comparing version 3.6.4 to 3.6.5
@@ -33,3 +33,3 @@ "use strict"; | ||
const create = context => { | ||
function validateQueryNode(nodeWithValueProp) { | ||
function isValidQueryNode(nodeWithValueProp) { | ||
const { | ||
@@ -40,15 +40,3 @@ query, | ||
} = (0, _assignmentAst.getQueryNodeFrom)(context, nodeWithValueProp); | ||
if (!query) { | ||
return { | ||
isDTLQuery: false, | ||
isValidElement: false | ||
}; | ||
} | ||
const isValidElement = query.match(/^(get|find|query)ByRole$/) && ["textbox", "dropdown"].includes(queryArg); | ||
return { | ||
isDTLQuery, | ||
isValidElement | ||
}; | ||
return !!query && isDTLQuery && !!query.match(/^(get|find|query)(All)?ByRole$/) && ["textbox", "dropdown"].includes(queryArg); | ||
} | ||
@@ -64,20 +52,12 @@ | ||
const queryNode = node.callee.object.arguments[0].object; | ||
const { | ||
isDTLQuery, | ||
isValidElement | ||
} = validateQueryNode(queryNode); | ||
function fix(fixer) { | ||
return [fixer.remove(context.getSourceCode().getTokenBefore(valueProp)), fixer.remove(valueProp), fixer.replaceText(matcher, "toHaveValue")]; | ||
} | ||
if (isDTLQuery) { | ||
if (isValidQueryNode(queryNode)) { | ||
context.report({ | ||
messageId, | ||
node, | ||
fix: isValidElement ? fix : undefined, | ||
suggest: isValidElement ? undefined : [{ | ||
desc: `Replace ${matcher.name} with toHaveValue`, | ||
fix | ||
}] | ||
fix(fixer) { | ||
return [fixer.remove(context.getSourceCode().getTokenBefore(valueProp)), fixer.remove(valueProp), fixer.replaceText(matcher, "toHaveValue")]; | ||
} | ||
}); | ||
@@ -94,20 +74,12 @@ } | ||
const matcher = node.callee.property; | ||
const { | ||
isDTLQuery, | ||
isValidElement | ||
} = validateQueryNode(queryNode); | ||
function fix(fixer) { | ||
return [fixer.removeRange([context.getSourceCode().getTokenBefore(valueProp).range[0], valueProp.range[1]]), fixer.replaceText(matcher, "toHaveValue")]; | ||
} | ||
if (isDTLQuery) { | ||
if (isValidQueryNode(queryNode)) { | ||
context.report({ | ||
messageId, | ||
node, | ||
fix: isValidElement ? fix : undefined, | ||
suggest: isValidElement ? undefined : [{ | ||
desc: `Replace ${matcher.name} with toHaveValue`, | ||
fix | ||
}] | ||
fix(fixer) { | ||
return [fixer.removeRange([context.getSourceCode().getTokenBefore(valueProp).range[0], valueProp.range[1]]), fixer.replaceText(matcher, "toHaveValue")]; | ||
} | ||
}); | ||
@@ -114,0 +86,0 @@ } |
{ | ||
"name": "eslint-plugin-jest-dom", | ||
"version": "3.6.4", | ||
"version": "3.6.5", | ||
"description": "ESLint plugin to follow best practices and anticipate common mistakes when writing tests with jest-dom", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
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
76314
1197