Skip to content

Files

Latest commit

 

History

History
55 lines (38 loc) · 1.38 KB

no-async-tests.md

File metadata and controls

55 lines (38 loc) · 1.38 KB

Pattern: Use of async/await in Cypress test case

Issue: -

Description

Cypress tests that return a promise will error and cannot run successfully. An async function returns a promise under the hood, so a test using an async function will also error.

Rule Details

This rule disallows using async test functions.

Examples of incorrect code for this rule:

describe('my feature', () => {
  it('my test case', async ()  => {
    await cy.get('.myClass')
    // other operations
  })
})
describe('my feature', () => {
  it('my test case', async ()  => {
    cy
    .get('.myClass')
    .click()

    await someAsyncFunction()
  })
})

Examples of correct code for this rule:

describe('my feature', () => {
  it('my test case', ()  => {
    cy.get('.myClass')
    // other operations
  })
})

When Not To Use It

If there are genuine use-cases for using async/await in your test cases then you may not want to include this rule (or at least demote it to a warning).

Further Reading