Skip to content

Commit 7fe8a49

Browse files
Merge pull request #198 from MikeMcC399/rule-doc-harmonization
docs: rule documentation harmonization
2 parents a8e36f7 + fa29884 commit 7fe8a49

9 files changed

+67
-30
lines changed

docs/rules/assertion-before-screenshot.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
## Assertion Before Screenshot
1+
# Require screenshots to be preceded by an assertion (`cypress/assertion-before-screenshot`)
22

3+
<!-- end auto-generated rule header -->
34
If you take screenshots without assertions then you may get different screenshots depending on timing.
45

56
For example, if clicking a button makes some network calls and upon success, renders something, then the screenshot may sometimes have the new render and sometimes not.
67

8+
## Rule Details
9+
710
This rule checks there is an assertion making sure your application state is correct before doing a screenshot. This makes sure the result of the screenshot will be consistent.
811

9-
Invalid:
12+
Examples of **incorrect** code for this rule:
1013

1114
```js
1215
cy.visit('myUrl');
1316
cy.screenshot();
1417
```
1518

16-
Valid:
19+
Examples of **correct** code for this rule:
1720

1821
```js
1922
cy.visit('myUrl');
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1-
## No Assigning Return Values
1+
# Disallow assigning return values of `cy` calls (`cypress/no-assigning-return-values`)
2+
3+
💼 This rule is enabled in the ✅ `recommended` config.
4+
5+
<!-- end auto-generated rule header -->
6+
## Further Reading
27

38
See [the Cypress Best Practices guide](https://on.cypress.io/best-practices#Assigning-Return-Values).

docs/rules/no-async-before.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
# Prevent using async/await in Cypress test cases (no-async-tests)
1+
# Disallow using `async`/`await` in Cypress `before` methods (`cypress/no-async-before`)
22

3-
Cypress commands that return a promise may cause side effects in before/beforeEach hooks, possibly causing unexpected behavior.
3+
<!-- end auto-generated rule header -->
4+
Cypress commands that return a promise may cause side effects in `before`/`beforeEach` hooks, possibly causing unexpected behavior.
45

56
## Rule Details
67

@@ -38,12 +39,11 @@ describe('my feature', () => {
3839
// other operations
3940
})
4041
})
41-
4242
```
4343

4444
## When Not To Use It
4545

46-
If there are genuine use-cases for using `async/await` in your before then you may not want to include this rule (or at least demote it to a warning).
46+
If there are genuine use-cases for using `async/await` in your `before` hooks then you may not want to include this rule (or at least demote it to a warning).
4747

4848
## Further Reading
4949

docs/rules/no-async-tests.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1-
# Prevent using async/await in Cypress test cases (no-async-tests)
1+
# Disallow using `async`/`await` in Cypress test cases (`cypress/no-async-tests`)
22

3-
Cypress tests [that return a promise will error](https://docs.cypress.io/guides/references/error-messages.html#Cypress-detected-that-you-returned-a-promise-from-a-command-while-also-invoking-one-or-more-cy-commands-in-that-promise) and cannot run successfully. An `async` function returns a promise under the hood, so a test using an `async` function will also error.
3+
💼 This rule is enabled in the ✅ `recommended` config.
4+
5+
<!-- end auto-generated rule header -->
6+
Cypress tests [that return a promise will error](https://docs.cypress.io/guides/references/error-messages.html#Cypress-detected-that-you-returned-a-promise-from-a-command-while-also-invoking-one-or-more-cy-commands-in-that-promise) and cannot run successfully.
7+
An `async` function returns a promise under the hood, so a test using an `async` function will also error.
48

59
## Rule Details
610

@@ -38,7 +42,6 @@ describe('my feature', () => {
3842
// other operations
3943
})
4044
})
41-
4245
```
4346

4447
## When Not To Use It

docs/rules/no-force.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
# disallow using of 'force: true' option (no-force)
1+
# Disallow using `force: true` with action commands (`cypress/no-force`)
22

3+
<!-- end auto-generated rule header -->
34
Using `force: true` on inputs appears to be confusing rather than helpful.
45
It usually silences the actual problem instead of providing a way to overcome it.
56
See [Cypress Core Concepts](https://docs.cypress.io/guides/core-concepts/interacting-with-elements.html#Forcing).
@@ -8,15 +9,15 @@ If enabling this rule, it's recommended to set the severity to `warn`.
89

910
## Rule Details
1011

11-
This rule aims to disallow using of the `force` option on:[`.click()`](https://on.cypress.io/click),
12+
This rule disallows using the `force` option on:[`.click()`](https://on.cypress.io/click),
1213
[`.dblclick()`](https://on.cypress.io/dblclick), [`.type()`](https://on.cypress.io/type),
1314
[`.rightclick()`](https://on.cypress.io/rightclick), [`.select()`](https://on.cypress.io/select),
1415
[`.focus()`](https://on.cypress.io/focus), [`.check()`](https://on.cypress.io/check),
1516
and [`.trigger()`](https://on.cypress.io/trigger).
17+
1618
Examples of **incorrect** code for this rule:
1719

1820
```js
19-
2021
cy.get('button').click({force: true})
2122
cy.get('button').dblclick({force: true})
2223
cy.get('input').type('somth', {force: true})
@@ -26,13 +27,11 @@ cy.get('input').rightclick({force: true})
2627
cy.get('input').check({force: true})
2728
cy.get('input').select({force: true})
2829
cy.get('input').focus({force: true})
29-
3030
```
3131

3232
Examples of **correct** code for this rule:
3333

3434
```js
35-
3635
cy.get('button').click()
3736
cy.get('button').click({multiple: true})
3837
cy.get('button').dblclick()
@@ -42,10 +41,8 @@ cy.get('input').rightclick({anyoption: true})
4241
cy.get('input').check()
4342
cy.get('input').select()
4443
cy.get('input').focus()
45-
4644
```
4745

48-
4946
## When Not To Use It
5047

5148
If you don't mind using `{ force: true }` with action commands, then turn this rule off.

docs/rules/no-pause.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
## Do not use `cy.pause` command
1+
# Disallow using `cy.pause()` calls (`cypress/no-pause`)
22

3-
It is recommended to remove [cy.pause](https://on.cypress.io/pause) command before committing the specs to avoid other developers getting unexpected results.
3+
<!-- end auto-generated rule header -->
4+
It is recommended to remove any [cy.pause](https://on.cypress.io/pause) commands before committing specs to avoid other developers getting unexpected results.
45

5-
Invalid:
6+
## Rule Details
7+
8+
Examples of **incorrect** code for this rule:
69

710
```js
811
cy.pause();
912
```
1013

11-
Valid:
14+
Examples of **correct** code for this rule:
1215

1316
```js
1417
// only the parent cy.pause command is detected
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1-
## No Unnecessary Waiting
1+
# Disallow waiting for arbitrary time periods (`cypress/no-unnecessary-waiting`)
2+
3+
💼 This rule is enabled in the ✅ `recommended` config.
4+
5+
<!-- end auto-generated rule header -->
6+
## Further Reading
27

38
See [the Cypress Best Practices guide](https://on.cypress.io/best-practices#Unnecessary-Waiting).
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
## Only allow `data-*` attribute selectors (require-data-selectors)
2-
only allow `cy.get` to allow selectors that target `data-*` attributes
1+
# Require `data-*` attribute selectors (`cypress/require-data-selectors`)
32

4-
See [the Cypress Best Practices guide](https://docs.cypress.io/guides/references/best-practices.html#Selecting-Elements).
3+
<!-- end auto-generated rule header -->
4+
Require `cy.get` to use only selectors that target `data-*` attributes.
55

66
> Note: If you use this rule, consider only using the `warn` error level, since using `data-*` attribute selectors may not always be possible.
77
8-
### Rule Details
8+
## Rule Details
9+
10+
Examples of **incorrect** code for this rule:
911

10-
examples of **incorrect** code with `require-data-selectors`:
1112
```js
1213
cy.get(".a")
1314
cy.get('[daedta-cy=submit]').click()
@@ -16,8 +17,13 @@ cy.get(".btn-large").click()
1617
cy.get(".btn-.large").click()
1718
```
1819

19-
examples of **correct** code with `require-data-selectors`:
20+
Examples of **correct** code for this rule:
21+
2022
```js
2123
cy.get('[data-cy=submit]').click()
2224
cy.get('[data-QA=submit]')
2325
```
26+
27+
## Further Reading
28+
29+
See [the Cypress Best Practices guide](https://docs.cypress.io/guides/references/best-practices.html#Selecting-Elements).
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1-
## Unsafe to chain command
1+
# Disallow actions within chains (`cypress/unsafe-to-chain-command`)
2+
3+
💼 This rule is enabled in the ✅ `recommended` config.
4+
5+
<!-- end auto-generated rule header -->
6+
### Options
7+
8+
<!-- begin auto-generated rule options list -->
9+
10+
| Name | Description | Type | Default |
11+
| :-------- | :---------------------------------------------------------- | :---- | :------ |
12+
| `methods` | An additional list of methods to check for unsafe chaining. | Array | `[]` |
13+
14+
<!-- end auto-generated rule options list -->
15+
16+
## Further Reading
217

318
See [retry-ability guide](https://docs.cypress.io/guides/core-concepts/retry-ability#Actions-should-be-at-the-end-of-chains-not-the-middle).

0 commit comments

Comments
 (0)