Skip to content

Commit

Permalink
call setTimeout with the right global scope to prevent 'this' f… (cyp…
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-mann authored and jennifer-shehane committed Nov 15, 2019
1 parent 5d2825c commit ff6bdcd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/driver/src/cy/timers.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const create = () => {

const invoke = (contentWindow, fnOrCode, params = []) => {
if (_.isFunction(fnOrCode)) {
return fnOrCode(...params)
return fnOrCode.apply(contentWindow, params)
}

return contentWindow.eval(fnOrCode)
Expand Down
11 changes: 11 additions & 0 deletions packages/driver/test/cypress/fixtures/issue-5707.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!doctype html>
<html lang="en">
<body>
<script>
'use strict';
window.setTimeout(function () {
this.foo = 'bar'
}, 50)
</script>
</body>
</html>
7 changes: 7 additions & 0 deletions packages/driver/test/cypress/integration/issues/5707_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// https://github.com/cypress-io/cypress/issues/5707
describe('issue 5707', () => {
it('calls setTimeout with the correct context', () => {
cy.visit('/fixtures/issue-5707.html')
cy.window().its('foo').should('eq', 'bar')
})
})

0 comments on commit ff6bdcd

Please sign in to comment.