Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Loading fixture with component test

Performing a Cypress component test, I load a fixture in a before hook.

The fixture loads, but disappears after the first test.

before(() => {
  cy.fixture('my-fixture').as('fixture')
})

it('test1', function() {
  mount(component, {
    propsData: {'data': this.fixture},
  })
})

it('test2', function() {
  mount(component, {
    propsData: {'data': this.fixture},  // undefined
  })
})

How do I fix the fixture?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Alises are cleared down between tests. You can change the hook to beforeEach() to allow all tests to see the data.

Note that the fixture is not read from disk every time it’s called, the cy.fixture() command has a cache the returns the previously read value on 2nd, 3rd calls.

beforeEach(() => {
  cy.fixture('my-fixture').as('fixture')
})

it('test1', function() {
  mount(component, {
    propsData: {'data': this.fixture},
  })
})

it('test2', function() {
  mount(component, {
    propsData: {'data': this.fixture},  // passes
  })
})
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading