Skip to content

Commit c1a540d

Browse files
Merge pull request #181 from MikeMcC399/mocha-instructions
docs: add mocha instructions to readme
2 parents 9499f42 + abafcd6 commit c1a540d

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,44 @@ Rules with a check mark (✅) are enabled by default while using the `plugin:cyp
128128
| | [require-data-selectors](./docs/rules/require-data-selectors.md) | Only allow data-\* attribute selectors (require-data-selectors) |
129129
| | [no-pause](./docs/rules/no-pause.md) | Disallow `cy.pause()` parent command |
130130

131+
## Mocha and Chai
132+
133+
Cypress is built on top of [Mocha](https://on.cypress.io/guides/references/bundled-libraries#Mocha) and [Chai](https://on.cypress.io/guides/references/bundled-libraries#Chai). See the following sections for information on using ESLint plugins [eslint-plugin-mocha](https://www.npmjs.com/package/eslint-plugin-mocha) and [eslint-plugin-chai-friendly](https://www.npmjs.com/package/eslint-plugin-chai-friendly) together with `eslint-plugin-cypress`.
134+
135+
## Mocha `.only` and `.skip`
136+
137+
During test spec development, [Mocha exclusive tests](https://mochajs.org/#exclusive-tests) `.only` or [Mocha inclusive tests](https://mochajs.org/#inclusive-tests) `.skip` may be used to control which tests are executed, as described in the Cypress documentation [Excluding and Including Tests](https://on.cypress.io/guides/core-concepts/writing-and-organizing-tests#Excluding-and-Including-Tests). To apply corresponding rules, you can install and use [eslint-plugin-mocha](https://www.npmjs.com/package/eslint-plugin-mocha). The rule [mocha/no-exclusive-tests](https://github.com/lo1tuma/eslint-plugin-mocha/blob/main/docs/rules/no-exclusive-tests.md) detects the use of `.only` and the [mocha/no-skipped-tests](https://github.com/lo1tuma/eslint-plugin-mocha/blob/main/docs/rules/no-skipped-tests.md) rule detects the use of `.skip`:
138+
139+
```sh
140+
npm install --save-dev eslint-plugin-mocha
141+
```
142+
143+
In your `.eslintrc.json`:
144+
145+
```json
146+
{
147+
"plugins": [
148+
"cypress",
149+
"mocha"
150+
],
151+
"rules": {
152+
"mocha/no-exclusive-tests": "warn",
153+
"mocha/no-skipped-tests": "warn"
154+
}
155+
}
156+
```
157+
158+
Or you can simply use the `cypress/recommended` and `mocha/recommended` configurations together, for example:
159+
160+
```json
161+
{
162+
"extends": [
163+
"plugin:cypress/recommended",
164+
"plugin:mocha/recommended"
165+
]
166+
}
167+
```
168+
131169
## Chai and `no-unused-expressions`
132170

133171
Using an assertion such as `expect(value).to.be.true` can fail the ESLint rule `no-unused-expressions` even though it's not an error in this case. To fix this, you can install and use [eslint-plugin-chai-friendly](https://www.npmjs.com/package/eslint-plugin-chai-friendly).

0 commit comments

Comments
 (0)