Skip to content

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

@flotwig

Description

@flotwig

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 🥝'])

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions