Cypress load data from json – fixture before

I am trying to retrieve some data from a json file via fixture in Cypress, but the data is not recognized at all.

before(() => {
cy.fixture('example').then(function (data) {
    console.log("this", data.user);
})

})

The console outputs the user, this is working.

But after that I have a step:

Given("I check data", () => {
    console.log("this", this.data.user);
});

And here the data is undefined.

I tried to set inside before also:

this.data = data but did not help. I also tried to use beforeEach with no success.

Source: Ask Javascript Questions

LEAVE A COMMENT