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

Alias in hooks #5223

Closed
prashantabellad opened this issue Sep 27, 2019 · 2 comments
Closed

Alias in hooks #5223

prashantabellad opened this issue Sep 27, 2019 · 2 comments

Comments

@prashantabellad
Copy link

prashantabellad commented Sep 27, 2019

This is an issue

Current behavior:

Consider below code where I am creating alias users in before hook.

before(function () {
  // alias the users fixtures
  cy.fixture('users.json').as('users')
})
I am not able to access it in my test below
it('utilize users in some way', () => {
  // access the users property
  const user = this.users[0]
})

I am able to only access it when I change anonymous "()=> { " to "function()=>{"
it('utilize users in some way', function() => {
  // access the users property
  const user = this.users[0]
})

Desired behavior:

Steps to reproduce: (app code and test code)

Versions

@jennifer-shehane
Copy link
Member

before code is only run once, and between the tests Cypress removes all of the aliases. So in subsequent tests it is not available.

Moving this code into a beforeEach will work.

Closing as duplicate of #665

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

3 participants
@jennifer-shehane @prashantabellad and others