Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using promisify in before or beforeEach doesn't work as expected #1

Open
NicholasBoll opened this issue Apr 21, 2018 · 0 comments
Open

Comments

@NicholasBoll
Copy link
Owner

.promisify seems to work perfectly well if used anywhere in an it block, but a before and beforeEach will exit early if .promisify is used in a before or beforeEach block and is not the last chain.

Example (doesn't work):

describe('when used with beforeEach', () => {
  beforeEach(async () => {
    await cy.wrap('foo').promisify()

    cy.get('body').should('not.exist') // assertion shows in the test, instead of the beforeEach hook
  })
  

  it('should not run any beforeEach commands in this block', () => {
    cy.wrap('bar').should('equal', 'bar')
  })
})

Example (works, but added await to every command after first await):

describe('when used with beforeEach', () => {
  beforeEach(async () => {
    await cy.wrap('foo').promisify()

    await y.get('body').should('not.exist').promisify() // works as expected
  })
  

  it('should not run any beforeEach commands in this block', () => {
    cy.wrap('bar').should('equal', 'bar')
  })
})

Switching the first example to use before results in a Cypress error:

CypressError: Cypress detected that you returned a promise from a command while also invoking one or more cy commands in that promise.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant