cy.intercept not intercepting the request
See original GitHub issueCurrent behavior
The XHR request finishes with Failed to fetch
even though the request is stubbed in beforeEach. (See screenshot, showing the routes being stubbed on the left, and the failed request in the network inspector)
Notes:
- This is flaky, re-running the test suite might end in a success.
- The stubbed request is for a domain different than the app
Desired behavior
Stubbed request should properly return the value they are given as a stub.
Test code to reproduce
This is the relevant part of the setup. I am well aware this is not a reproduction but there is no easy way to make a small reproduction.
Any pointers, tips, suggestion is more than welcome. I’ve been trying to solve this for a while now
const iofogControllerInfo = {
baseURL: 'http://localhost:51121',
credentials: {
username: '',
password: ''
}
}
const applications = [{
name: 'Cypress application',
id: 1,
routes: [],
microservices: [],
isActivated: true
}]
const microservices = []
const GET_APP_MICROSERVICES = (name) => `/microservices?application=${encodeURIComponent(name)}`
beforeEach(() => {
// ... Bunch of other intercepts
cy.intercept('GET', `${iofogControllerInfo.baseURL}${GET_APP_MICROSERVICES(applications[0].name)}`, { statusCode: 200, body: { microservices } }).as('getMicroservices')
})
Cypress Version
7.9.0 ~ 8.2.0 (Tried them all)
Other
No response
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:5
Top Results From Across the Web
cy.intercept() not stubbing API in Cypress - Stack Overflow
I managed to get stubbing working with the pattern @eric99 gave, ... cy.intercept() will not work as the API call is done server-side....
Read more >Cypress cy.intercept Problems - Gleb Bahmutov
The command cy.intercept can match requests using a substring, a minimatch, or a regular expression. By default, it intercepts requests matching ...
Read more >intercept - Cypress Documentation
The lifecycle of a cy.intercept() interception begins when an HTTP request is sent from your app that matches one or more registered cy.intercept()...
Read more >Unable to intercept request using cy.intercept #20536 - GitHub
I've read the docs repeatedly and tried different versions of the interceptor syntax, but it never intercepts. Is this a bug? Desired behavior....
Read more >A Practical Guide to Intercepting Network Requests in Cypress
Our .intercept() command is now matching any request that contains the url ... command does not actually wait for our network request to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Got the same problem. I use
intercept
andreq.reply
to stub the response and it sometimes succeeds, sometimes not test preview:Mine fails because cypress isn’t recognizing that the request has returned.
The first test succeeds but then other tests fail.