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

Add API for cy.intercept() to only reply to the first N requests #8531

Closed
flotwig opened this issue Sep 9, 2020 · 3 comments · Fixed by #14513
Closed

Add API for cy.intercept() to only reply to the first N requests #8531

flotwig opened this issue Sep 9, 2020 · 3 comments · Fixed by #14513
Assignees
Labels
topic: cy.intercept() type: enhancement Requested enhancement of existing feature

Comments

@flotwig
Copy link
Contributor

flotwig commented Sep 9, 2020

Current behavior:

To change the response for a route over time, currently, the user must implement counting themselves:

      let k = 0;
      cy.intercept('/favorite-fruits', (req) => {
        k += 1
        switch (k) {
          case 1:
            return req.reply(['apples 🍎'])
          case 2:
            return req.reply(['grapes 🍇'])
          case 3:
            return req.reply(['kiwi 🥝'])
          default:
            return
        }
      })

Desired behavior:

There is an API for the user to specify the number of times to use a route's handler. Something like this:

cy.intercept({ url: '/favorite-fruits', times: 1 }, ['apples 🍎'])
cy.intercept({ url: '/favorite-fruits', times: 1 }, ['grapes 🍇'])
cy.intercept({ url: '/favorite-fruits', times: 1 }, ['kiwi 🥝'])
@flotwig flotwig added type: enhancement Requested enhancement of existing feature topic: cy.intercept() internal-priority labels Sep 9, 2020
@jennifer-shehane jennifer-shehane changed the title Add API for cy.route2 to only reply to the first N requests Add API for cy.intercept() to only reply to the first N requests Dec 3, 2020
@cypress-bot cypress-bot bot added stage: work in progress stage: needs review The PR code is done & tested, needs review and removed stage: work in progress labels Jan 12, 2021
@flotwig
Copy link
Contributor Author

flotwig commented Feb 8, 2021

A quick update to those waiting on this feature - we still plan to release this, but not before fixing #9302, since we want to avoid users using times to create hacky/brittle workarounds for #9302.

@cypress-bot cypress-bot bot added stage: to do and removed stage: needs review The PR code is done & tested, needs review labels Apr 27, 2021
@cypress-bot cypress-bot bot added stage: work in progress stage: needs review The PR code is done & tested, needs review and removed stage: waiting labels May 5, 2021
@cypress-bot cypress-bot bot added stage: pending release and removed stage: needs review The PR code is done & tested, needs review labels May 10, 2021
@cypress-bot
Copy link
Contributor

cypress-bot bot commented May 10, 2021

The code for this is done in cypress-io/cypress#14513, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented May 10, 2021

Released in 7.3.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v7.3.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators May 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
topic: cy.intercept() type: enhancement Requested enhancement of existing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants