https://cypress.io logo
Cypress Electron dataLayer is not defined
# i-need-help
s
I'm confused by this. If I run a
--headed
test and turn on developer tools, go to console and enter
dataLayer
- I get an error that
dataLayer is not defined
. This isn't the case in Chrome with the app running. I've entered
window.dataLayer = window.dataLayer || []
and then clicked buttons (that should be firing events into the dataLayer) but it remains blank. I previously had a test that was asserting the dataLayer fine, so this is really puzzling why the dataLayer is now disappeared. Have I done something daft in a config or something?
Copy code
cy.window()
      .its('dataLayer')
      .then(dataLayer => {
        const size = Cypress.$(dataLayer).length - 1
        const event = dataLayer[size]

        expect(event.event).to.equal(expectedEvents.event)
        expect(event.action).to.equal(expectedEvents.action)
      })