intercept leaks between tests when combined with aliases
See original GitHub issueCurrent behavior
Using aliases in combination with intercept causes tests to interfere with other tests regularly.
Desired behavior
Intercept is cleaned up properly between tests.
Test code to reproduce
The below test will reproduce this. For me it reproduces it about 60% of the time. I can reproduce it 100% of the time in the closed source test where I encountered the issue, perhaps because it has a lot more assertions. I suppose it may depend on your hardware.
It seems that the error disappears if I clear cookies in afterEach
.
const url = 'https://www.cypress.io/'
const dummyRequest = () =>
cy.request({
url,
})
context('InterceptBug', () => {
beforeEach(() => {
dummyRequest().as('home')
cy.visit(url)
})
// afterEach(() => {
// cy.clearCookies()
// })
it('shows the logo', () => {
cy.get('[alt="Cypress.io"]').should('exist')
})
const navigate = () => {
cy.get('[alt="Cypress.io"]').should('exist')
// The second time this is called, this sometimes triggers an additional
// error: `Cannot read property 'fireChangeEvent' of undefined`
// Other times it will fail on the previous selector with the (assert)
// error: `expected undefined to exist`
// I figured those are different bugs, so consider them out of scope for
// this issue.
cy.intercept(url).as('navigation')
cy.contains('Features').click({
force: true,
})
cy.wait('@navigation')
// If the below visit is removed the test should succeed most of the time
cy.visit(url)
}
it('allows navigating', navigate)
it('allows navigating2 very irregularly fails', navigate)
const useHomeAlias = () => {
cy.get<string>('@home').then((response) => {
// do something with response
dummyRequest()
})
}
// cy.get() could not find a registered alias for: @home.
// You have not aliased anything yet.
it('use home alias fails', useHomeAlias)
it('use home alias succeeds', useHomeAlias)
})
export {}
Versions
Cypress version 6.0.0, N/A, Chrome 87, macOS Catalina, N/A
Possibly related issues:
Issue Analytics
- State:
- Created 3 years ago
- Reactions:9
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Cypress cy.intercept Problems - Gleb Bahmutov
Unfortunately overwriting cy. intercept has a bug with aliases #9580, and thus we cannot always show when the intercept is registered. We can ......
Read more >How to access alias in different test? - cypress - Stack Overflow
Show activity on this post. I have an alias defined in 1 test and I would like to use the result in a...
Read more >Best Practices - Cypress Documentation
Anti-Pattern: Coupling multiple tests together. Best Practice: Tests should always be able to be run independently from one another and still pass ....
Read more >Cypress Aliases Intercepted Routes - ProgramsBuzz
We can use this fake response and use that particular JSON data to do tests afterward. Once the actual API is created we...
Read more >Spectral leakage - Wikipedia
... produces leakage, which we call aliases of the original spectral component. For Fourier transform purposes, sampling is modeled as a product between...
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
I can’t always get the tests to fail, but it pretty reliably fails with the example below. I could never get the
allows navigating2 very irregularly fails
test to fail, so if you have a simpler example of this, please provide it or open a new issue.I’m not totally sure this is related to intercept exactly, it seems like a combination of things are involved.
Reproducible Example
The ‘use home alias fails’ test doesn’t seem to be running the
beforeEach
hook.This has been resolved and is no longer present in our most recent version - 6.2.1