Skip to content
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

fix: Add missing error message when req.continue is used incorrectly #25884

Merged
merged 3 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ _Released 03/1/2023 (PENDING)_
- Added missing TypeScript type definitions for the [`cy.reload()`](https://docs.cypress.io/api/commands/reload) command. Addressed in [#25779](https://github.com/cypress-io/cypress/pull/25779).
- Ensure Angular components are mounted inside the correct element. Fixes [#24385](https://github.com/cypress-io/cypress/issues/24385)
- Fix a bug where files outside the project root in a monorepo are not correctly served when using Vite. Addressed in [#25801](https://github.com/cypress-io/cypress/pull/25801)
- Fixed an issue where using [`cy.intercept`](https://docs.cypress.io/api/commands/intercept)'s `req.continue()` with a non-function parameter would not provide an appropriate error message. Fixed in [#25884](https://github.com/cypress-io/cypress/pull/25884).

**Misc:**

Expand Down
24 changes: 24 additions & 0 deletions packages/driver/cypress/e2e/commands/net_stubbing.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2496,6 +2496,30 @@ describe('network stubbing', { retries: 15 }, function () {
}).visit('/dump-method')
})

it('fails test if both req.reply and req.continue are called in req handler', function (done) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just adding an extra test I noticed was missing- there was existing coverage for using req.reply multiple times but not for using both reply and continue in a single handler

testFail((err) => {
expect(err.message).to.contain('`req.reply()` and/or `req.continue()` were called to signal request completion multiple times, but a request can only be completed once')
done()
})

cy.intercept('/dump-method', function (req) {
req.reply()

req.continue()
}).visit('/dump-method')
})

it('fails test if req.continue is called with a non-function parameter', function (done) {
testFail((err) => {
expect(err.message).to.contain('\`req.continue\` requires the parameter to be a function')
done()
})

cy.intercept('/dump-method', function (req) {
req.continue({} as any)
}).visit('/dump-method')
})

it('fails test if req.reply is called after req handler finishes', function (done) {
testFail((err) => {
expect(err.message).to.contain('> `req.reply()` was called after the request handler finished executing')
Expand Down
1 change: 1 addition & 0 deletions packages/driver/src/cypress/error_messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,7 @@ export default {

You passed: ${format(eventName)}`, 10)
},
req_continue_fn_only: '\`req.continue\` requires the parameter to be a function',
event_needs_handler: `\`req.on()\` requires the second parameter to be a function.`,
defineproperty_is_not_allowed: `\`defineProperty()\` is not allowed.`,
setprototypeof_is_not_allowed: `\`setPrototypeOf()\` is not allowed.`,
Expand Down