Closed AwarePL closed 4 years ago
If you want to share context across tests, you'll want to use the standard function definition, instead of arrow functions: https://on.cypress.io/variables-and-aliases#Avoiding-the-use-of-this
before(() => {
this.consts = 'foo'
})
// function definition, not arrow function
it("test", function () {
expect(this.consts).to.be.ok
})
I feel like this was likely a bug fix from the previous version. 🤔
sure, in my other project currently at 4.10 arrow function still works. You are saying it was faulty all along in prev versions?
example:
describe('sample End to end test suite', () => {
before(() => {
cy.fixture('testsParms').then((parms) => {
this.parms = parms
})
})
beforeEach(() => {
cy.visit('')
})
it('test', () => {
step1()
step2(this.parms.fixture.node[0])
})
I'm guessing this is related to the 5.0 change making the default preprocessor webpack
instead of browserify
, which handles this
differently. (in the working code, I think this
is the global window
). So yes, that code working in previous versions wasn't intended
OK, thanks for clarification. ;)
Current behavior:
Using
cy.fixture
same as on code sample provided in docs/api i get following error:Test code to reproduce
Versions
Chrome 84 Windows 10 Cypress 5.0.0