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

Comments

@jennifer-shehane
Copy link
Member

@jennifer-shehane jennifer-shehane commented Nov 14, 2019

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

@cypress-bot

This comment has been minimized.

Copy link

@cypress-bot 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

This comment has been minimized.

Copy link

@cypress-bot 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
1 participant
You can’t perform that action at this time.