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

docs: direct assignment to global window properties not supported by jsdom #9287

Closed
vvanpo opened this issue Dec 9, 2019 · 1 comment · Fixed by #9288
Closed

docs: direct assignment to global window properties not supported by jsdom #9287

vvanpo opened this issue Dec 9, 2019 · 1 comment · Fixed by #9288

Comments

@vvanpo
Copy link
Contributor

vvanpo commented Dec 9, 2019

🐛 Bug Report

It is a known issue (#890 (comment)) that assigning properties on window fails silently, yet the documentation still recommends it:
https://github.com/facebook/jest/blob/v24.9.0/docs/ManualMocks.md#mocking-methods-which-are-not-implemented-in-jsdom

Can we update the docs to use

Object.defineProperty(window, 'matchMedia', {
  writable: true,
  value: {
    matches: false,
    media: query,
    onchange: null,
    addListener: jest.fn(),
    removeListener: jest.fn(),
  },
});
vvanpo added a commit to vvanpo/jest that referenced this issue Dec 9, 2019
Direct assignments to `window` properties fails silently if they are not
writable, so `Object.defineProperty()` should be used when stubbing
global properties.

Closes jestjs#9287
@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 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant