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.

Count number of times intercepted route was called

See original GitHub issue

What would you like?

Intercepted routes should keep track of the number of times they were called.

I’d like to gy.get the intercepted route and verify it was called N times.

I could put a custom property on the Req object and increment it in the RouteHandler but that is clunky, and not something the client should have to maintain. This seems to be the responsibility of the testing framework.

Why is this needed?

An essential part of testing is confirming your code is only making network requests the expected number of times. This should be baked in to the testing framework. If my code makes unnecessary requests, then my code is wrong, and I need to know about it.

SO post: https://stackoverflow.com/questions/67643208/verify-number-of-times-request-was-made

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
pstephenwillecommented, May 28, 2021

While there are clumsy work arounds, the ability to count the number of times a network request was made is fundamental to a testing library. This should be baked in to Cypress.

3reactions
jennifer-shehanecommented, May 24, 2021

@pstephenwille You can do this with the cy.get('@alias.all') which is undocumented but I believe we’ll be documenting it soon.

cy.intercept('POST', 'my-url').as('postUrl')

// do stuff in your tests/app

// by this time this should have POSTed 4 times
cy.get('@postUrl.all').should('have.length', 4)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Verify number of times request was made - cypress
Using cy.spy() as a routeHandler allows a timeout to be set on the code that checks the call count. it('counts intercepts' ...
Read more >
Cypress cy.intercept Problems - Gleb Bahmutov
Count intercepts (again) #. We can count the number of times the intercept was called. 1 2
Read more >
intercept - Cypress Documentation
routeMatcher is an object used to match the incoming HTTP requests with this intercepted route. All properties are optional but all those that...
Read more >
A Practical Guide to Intercepting Network Requests in Cypress
intercept () can route almost any type of request, we can use it to match a network call for a static assets, e.g....
Read more >
Network Requests with Cypress by Cecelia Martinez - GitNation
So this image is from a presentation called how cy.intercept works, ... function to set the count, the number of times that it's...
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