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

The context of window is undefined when called within a setTimeout during strict mode #5707

Closed
jennifer-shehane opened this issue Nov 14, 2019 · 2 comments · Fixed by #5709 · May be fixed by ngChile/ngx-devkit-cypress-builder#20 or qsays/grafana#1
Labels
pkg/driver This is due to an issue in the packages/driver directory type: bug

Comments

@jennifer-shehane
Copy link
Member

Current behavior:

The context of window is undefined when called within a setTimeout during strict mode - originally found in this issue: #5698

Desired behavior:

this should be window - not undefined.

Steps to reproduce: (app code and test code)

index.html

<!doctype html>
<html lang="en">
<body>
  <script>
    'use strict';
    window.setTimeout(function () {
      this.foo = 'bar'
    }, 50)
  </script>
</body>
</html>

spec.js

it('asserts', () => {
  cy.visit('index.html')
  cy.window().its('foo').should('eq', 'bar')
})

Versions

Cypress 3.6.1

To Fix

This line of code below should be changed to:

return fnOrCode.apply(contentWindow, params)

https://github.com/cypress-io/cypress/blob/develop/packages/driver/src/cy/timers.js#L22:L22

I've confirmed this fixes the issue

@jennifer-shehane jennifer-shehane added type: bug pkg/driver This is due to an issue in the packages/driver directory labels Nov 14, 2019
@cypress-bot cypress-bot bot added the stage: ready for work The issue is reproducible and in scope label Nov 14, 2019
@cypress-bot cypress-bot bot added stage: work in progress stage: needs review The PR code is done & tested, needs review and removed stage: ready for work The issue is reproducible and in scope stage: work in progress labels Nov 15, 2019
@cypress-bot cypress-bot bot added stage: pending release and removed stage: needs review The PR code is done & tested, needs review labels Nov 15, 2019
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Nov 15, 2019

The code for this is done in cypress-io/cypress#5709, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Nov 27, 2019

Released in 3.7.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg/driver This is due to an issue in the packages/driver directory type: bug
Projects
None yet
1 participant