https://cypress.io logo
Network requests from 1st test are lingering into ...
# i-need-help
c
Hi all, Let's say I have two tests running one after the other, test #1 and test #2 #1 finishes. Sometimes there are still network requests going in/out of the application #2's beforeEach begins, which (1) clears my DB and (2) seeds by DB Sometimes these network requests still linger even after my DB is cleared in #2's beforeEach. This causes my application to throw an authentication error, as the requests are trying to check if they are from an authenticated session, but the DB is cleared --- Is there any way to prevent these requests from test #1 lingering into test #2's beforeEach? I know that Cypress has done this by design (https://docs.cypress.io/guides/references/best-practices#Dangling-state-is-your-friend)... but it seems harmful in this case. I would expect the "dangling state" to go away in the subsequent test's beforeEach
g
But how would Cypress "know" if your dangling network calls have finished or not?
c
I'm thinking it doesn't matter - if the test has either failed or passed already, it shouldn't matter if the dangling network calls have finished or not. We got a result from the test, and we should move on to the next test with a clean slate. That's just my thinking of course, based on this one issue I'm experiencing.
I know Cypress emphasizes "test isolation" (https://docs.cypress.io/guides/core-concepts/test-isolation) Does that not include network calls? Where does Cypress' own test isolation protocol occur?
g
The browser has the test isolation, it is YOUR server that is still processing the network calls, no?
c
Yeah you're right, my server is still processing the requests. I think that the browser is still sending them after the test result, though. I should look into that more closely. Stepping out of Cypress help realm with this question, but is there any programatic equivalent to hitting this button, lol. If I could do that in my beforeEach, that would ensure that no more network requests are sent and I can safely "db:clear".
Gonna give that a go
b
my memory is hazy on this - but are you using cy12? It should accomplish what you want with its stronger test isolation.
4 Views