Skip to content

doc: add note about return'ing after Cypress.stop() #6203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/api/cypress-api/stop.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ To ensure tests stop immediately after a failure across any spec file, add the f
afterEach(function () {
if (this.currentTest.state === 'failed') {
Cypress.stop()
return
}
})
```
Expand All @@ -45,12 +46,22 @@ beforeEach(() => {
if (env !== 'expected-condition') {
cy.log('Stop tests - environment is not setup correctly')
Cypress.stop()
return
}
})
```

## Notes

Calling `Cypress.stop()` will stop the execution of remaining tests, but any code after `Cypress.stop()` in the same container block (such as `beforeEach` or `afterEach`) will still run. To prevent additional logic from executing after `Cypress.stop()`, add a `return` statement immediately after it:

```javascript
if (someCondition) {
Cypress.stop()
return // Prevents further code execution in this block
}
```

### `cypress run` vs `cypress open` behavior

Calling `Cypress.stop()` during `cypress run` will skip any remaining tests in the current specfile. If recording to Cypress Cloud, all screenshots, videos, and [Test Replay](/cloud/features/test-replay) will still successfully upload.
Expand Down