Skip to content

[Bug]: jest-mock 29.2.0 does not allow spying on window.dispatchEvent anymore #13466

Closed

Description

Version

29.2.0

Steps to reproduce

  1. Clone https://github.com/chbiel/jest-global-bug
  2. cd jest-global-bug

npm

  1. cp package-npm.json package.json && npm install && npm test => works
  2. rm package.json && rm package-lock.json && rm -rf node_modules && cp package-npm-broken.json package.json && npm install && npm test => does not work

yarn

  1. cp package-yarn.json package.json && npm install && npm test => works (i was not able to pin jest to 29.1 with yarn. always results in a broken dependency tree somehow. So I used the also working version 28)
  2. rm package.json && rm yarn.lock && rm -rf node_modules && cp package-yarn-broken.json package.json && npm install && npm test => does not work

Expected behavior

jest.spyOn(global.window, 'dispatchEvent'); does not throw an error dispatchEvent property does not exist.

Same with window.window and similar.

Actual behavior

jest.spyOn(global.window, 'dispatchEvent'); does throw an error dispatchEvent property does not exist after upgrading (I think) jest-mock to version 29.2.0.

I am not 100% sure but I think it's related to this change: #13398

Additional context

No response

Environment

System:
    OS: Linux 5.4 Ubuntu 20.04.5 LTS (Focal Fossa)
    CPU: (6) x64 Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz
  Binaries:
    Node: 16.13.1 - ~/.nvm/versions/node/v16.13.1/bin/node
    Yarn: 1.17.3 - /usr/bin/yarn
    npm: 8.3.0 - ~/.nvm/versions/node/v16.13.1/bin/npm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions