eslint-plugin-cypress 6.2.0 → 6.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,6 +10,10 @@ Require `cy.get` to use only selectors that target `data-*` attributes.
10
10
 
11
11
  ## Rule Details
12
12
 
13
+ This rule checks the first parameter of each `cy.get`. It supports template literals, variable (re-)assignments and conditional expressions. For conditionals, all branches must conform to this rule.
14
+
15
+ Cypress aliases (as defined by `cy.as`) are always allowed.
16
+
13
17
  Examples of **incorrect** code for this rule:
14
18
 
15
19
  ```js
@@ -18,6 +22,7 @@ cy.get('[daedta-cy=submit]').click()
18
22
  cy.get('[d-cy=submit]')
19
23
  cy.get('.btn-large').click()
20
24
  cy.get('.btn-.large').click()
25
+ cy.get(condition ? "[data-cy=submit]" : ".btn-large")
21
26
 
22
27
  const CLASS_SELECTOR = ".my-class";
23
28
  cy.get(CLASS_SELECTOR)
@@ -36,6 +41,7 @@ Examples of **correct** code for this rule:
36
41
  cy.get('[data-cy=submit]').click()
37
42
  cy.get('[data-QA=submit]')
38
43
  cy.get(`[data-QA=submit]`)
44
+ cy.get(condition ? "[data-cy=submit]" : "[data-QA=submit]")
39
45
 
40
46
  const ASSESSMENT_SUBMIT = "[data-cy=assessment-submit]"
41
47
  cy.get(ASSESSMENT_SUBMIT).click()
@@ -62,6 +62,11 @@ function isDataNode(firstArg, dataVariables) {
62
62
  return dataVariables.has(firstArg.name)
63
63
  }
64
64
 
65
+ if (firstArg.type === 'ConditionalExpression') {
66
+ return isDataNode(firstArg.consequent, dataVariables)
67
+ && isDataNode(firstArg.alternate, dataVariables)
68
+ }
69
+
65
70
  return false
66
71
  }
67
72
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-cypress",
3
- "version": "6.2.0",
3
+ "version": "6.2.1",
4
4
  "description": "An ESLint plugin for projects using Cypress",
5
5
  "main": "./lib/index.js",
6
6
  "exports": {