Cypress commands that return a promise may cause side effects in before
/beforeEach
hooks, possibly causing unexpected behavior.
This rule disallows using async
before
and beforeEach
functions.
Examples of incorrect code for this rule:
describe('my feature', () => {
before('my test case', async () => {
await cy.get('.myClass')
// other operations
})
})
describe('my feature', () => {
before('my test case', async () => {
cy
.get('.myClass')
.click()
await someAsyncFunction()
})
})
Examples of correct code for this rule:
describe('my feature', () => {
before('my test case', () => {
cy.get('.myClass')
// other operations
})
})
If there are genuine use-cases for using async/await
in your before
hooks then you may not want to include this rule (or at least demote it to a warning).