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

Mocking window not working on Node >= 7.3 #2785

Closed
alexjoverm opened this issue Feb 2, 2017 · 7 comments
Closed

Mocking window not working on Node >= 7.3 #2785

alexjoverm opened this issue Feb 2, 2017 · 7 comments

Comments

@alexjoverm
Copy link
Contributor

Bug
I've been using the following code for mocking the window (in TS, but should be the same for js). It used to work:

interface MockWindow extends Window {
  addEventListener: jest.Mock<{}> & typeof window.addEventListener
  removeEventListener: jest.Mock<{}> & typeof window.removeEventListener
}
function getMockWindow() {
  window.addEventListener = jest.fn()
  window.removeEventListener = jest.fn()
  return window as MockWindow
}
let mockWindow = getMockWindow()

But now is not mocking the window correctly. So cannot check calls or call mockClear and that stuff:

mockWindow.addEventListener.mockClear() // doesn't find the method

Curiously, it was happening in my TravisCI as well, but I stop caching node_modules (I was doing it) and now works again. But still locally I having that issue. Any clue?

You could reproduce it like this

git clone https://github.com/coosto/ShortcutJS
yarn install
yarn run test -- --no-cache

Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.

  • Windows 10
  • jest 18.1.0
  • yarn 0.18.1
  • npm 4.0.5
  • node 7.4.0
@alexjoverm
Copy link
Contributor Author

Ok, new info -> in Node <= 7.2 works. Node > 7.2 fails.... Is there some known incompatibility issues?

@alexjoverm alexjoverm changed the title Mocking window not working anymore Mocking window not working on Node >= 7.3 Feb 2, 2017
@thymikee
Copy link
Collaborator

thymikee commented Feb 2, 2017

Maybe it's some kind of regression in Node, but nothing I've heard before.

@alexjoverm
Copy link
Contributor Author

Ok, new info again... This is crazy.

  • Node <= 7.2: works
  • Node 7.3, 7.4: doesn't work
  • Node 7.5: works again

WTF?

@alexjoverm
Copy link
Contributor Author

P.D.: perhaps we could close it, still I'm very curious about the issue

@alexjoverm
Copy link
Contributor Author

alexjoverm commented Feb 6, 2017

Ok, confirmed. I've just found @cpojer opened an issue and there is a regression in Node 7.3 (fixed by 7.5) that breaks some things nodejs/node#10492

This should be communicated somewhere in the docs, right? cc @thymikee

@cpojer
Copy link
Member

cpojer commented Feb 6, 2017

Yup, that's a node issue. Let's look past this and never speak of Node 7.3 and Node 7.4 again.

@cpojer cpojer closed this as completed Feb 6, 2017
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants