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

Fix code example for window:before:load and google analytics stubbing #1454

Closed
chrisbreiding opened this Issue Feb 27, 2019 · 0 comments

Comments

2 participants
@chrisbreiding
Copy link
Contributor

chrisbreiding commented Feb 27, 2019

The code example here should use the following:

    const ga = cy.stub().as('ga')

    cy.on('window:before:load', (win) => {
      Object.defineProperty(win, 'ga', {
        configurable: false,
        get: () => ga, // always return the stub
        set: () => {} // don't allow actual google analytics to overwrite this property
      })
    })

The current code doesn't work because it throws due to writeable: false when the actual google analytics tried to define window.ga

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.