Important Information
The original question here was not directly about the lack of support for the fetch api in Cypress, but that was the cause for the problem I initially posted here. I've edited the title of the question and added this preamble here. Below this paragraph is the original content of the question:
Original question
The Cypress documentation is filled with examples where you can set an alias to a particular web request, and then you can instruct cypress to wait on it. Like for instance, this one:
cy.route('POST', '/login').as('postLogin')
cy.get('input[name=username]').type('jane.lae')
cy.get('input[name=password]').type('password123{enter}')
// we should always explicitly wait for
// the response for this POST to come back
// so our tests are not potentially flaky or brittle
cy.wait('@postLogin')
The thing is I'm trying to use this exact technique in my app's tests, but I need to wait on a request that is not made against the same server where the app is hosted. Therefore I am assuming that I can type in the full URL of the backend endpoint, so that cy.route
does not prepend the baseUrl
, which is the host of where the frontend app is hosted.
// The following URL points to a backend rails app
// The frontend app I'm testing with cypress is at http://localhost:8080
cy.route('POST', 'http:/localhost:3000/session').as('postLogin')
// ... fill login form
cy.wait('@postLogin')
// The test never reaches this point
However, when I run my test, I get a timeout because cypress never realizes the request was performed, it continues to wait on it until it timeouts. Turns out when I inspect the test script on the left sidebar in the browser where cypress is running, the route has the explicit host I set, not only the path, but still the test stayed waiting for this request to occur, and it says it never occurs. When I inspect the network tab of the browser dev tools I can see the request occurred. And I can see in the terminal where my backend app is running, that it was indeed hit with a login request. Furthermore, I can see in my frontend app running in cypress' browser session, that the user signed in successfully and the app was redirected to the intended page after request.
The question is: can I make cypress aware of cross-origin requests so that it can wait for them? If so, how?
Update:
Stubbed routes are also not caught by cypress, and I cannot wait on them, or prevent them from occurring, as it is expected for stubbed requests.