question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Intercept not working with axios interceptors

See original GitHub issue

Current behavior

When trying to intercept an API call using cy.intercept, combined with axios which is using an interceptor, the test fails due to a network error.

I’ve created a demo project (using Vue) to showcase this issue. It only happens when opening Cypress in interactive mode, when running Cypress using npx cypress run, the error does not occur.

The project is very simple. There is a DemoAPI class (src/common/demo-api.ts), which extends a base API class (APIAbstract at src/common/api-abstract.ts). The DemoAPI class has a function to call an endpoint at http://localhost:3838/demo. The abstract API class also defines interceptors for axios. The DemoAPI endpoint is called in src/views/HomeView.vue.

The test inside tests/e2e/spec/demo.cy.ts is very basic. It visits the site and does a cy.intercept on the URL specified above.

When running the test, by first starting the frontend npm run serve, then starting Cypress in interactive mode npx cypress open and then running demo.cy.ts, this is the result:

Bildschirmfoto 2022-06-08 um 15 53 55

The axios interceptors seem to be the problem. When commenting out the axios interceptors, the test works. Also when running the tests headless using npx cypress run, the tests work.

Testing the same thing on a Windows machine seems not to produce the error and work just fine.

Desired behavior

Cypress should not throw an error with the axios interceptors active.

Test code to reproduce

This is the demo project, which showcases the error.

Cypress Version

10.0.3

Other

OS: macOS 12.4 Processor Architecture: Apple Silicone Browser: Electron 18.0.4

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rachelrudermancommented, Jun 27, 2022

Hi @svelver, thank you for your patience! We marked this issue as a bug and have forwarded it to be prioritized by the team 😸

0reactions
brabanodcommented, Aug 24, 2022

@flotwig I can confirm, that the request is being sent.

Bildschirmfoto 2022-08-24 um 08 09 44

Also disabling the cache in Chrome developer tools does not seem to help. Still it occasionally fails.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Axios request interceptor is not working in my vue app
I'm trying to make axios working with a request interceptor. However before a request is made the interceptor is not triggered. What could...
Read more >
How to use Axios interceptors to handle API error responses
Use axios interceptors instead! A better and simple way to handle the same problem, in a centrealized way, is to use axios interceptors...
Read more >
Setting up Axios Interceptors for all HTTP calls in an application
The first code example I will show is how to set up an Axios request interceptor. The example is written inside of a...
Read more >
How to Implement a Request Interceptor Like Axios
Axios ' interceptor is one of the reasons I like to use axios in my project, it makes the code of request-related more...
Read more >
Axios interceptor not updating request : r/reactjs - Reddit
reject(error); } ); authInstance.interceptors.response.use( (res) => { return res; }, async (err) => { const prevRequest = err?.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found