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

TypeError: Cannot redefine property: inert #8373

Closed
bjankord opened this issue Apr 24, 2019 · 4 comments
Closed

TypeError: Cannot redefine property: inert #8373

bjankord opened this issue Apr 24, 2019 · 4 comments

Comments

@bjankord
Copy link

🐛 Bug Report

When importing the WICG Inert Polyfill in a react component that we test with Jest, our Jest tests started failing with the following error message:

TypeError: Cannot redefine property: inert

This seems to be triggered by the WICG Inert polyfill using Object.defineProperty on the Element prototype

I believe this is an issue with JSDOM but is manifesting when using Jest. I tried setting the --no-cache flag when running Jest to no avail.

To Reproduce

I'm working on creating a repo to reproduce this issue.
This should be reproducible by creating a react component that imports WICG Inert Polyfill and then trying to test it with Jest.

Expected behavior

A way to use the inert polyfill with Jest is documented.

Link to repl or repo (highly encouraged)

I'm working on creating a repo to reproduce this issue and will post a link once I get the reduced test case put together.

Run npx envinfo --preset jest

  System:
    OS: macOS Sierra 10.12.6
    CPU: (8) x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
  Binaries:
    Node: 8.11.3 - ~/.nvm/versions/node/v8.11.3/bin/node
    Yarn: 1.12.3 - /usr/local/bin/yarn
    npm: 5.6.0 - ~/.nvm/versions/node/v8.11.3/bin/npm
  npmPackages:
    jest: ^23.1.0 => 23.6.0
@timbomckay
Copy link

I created an issue on the inert package to only define the property if it hasn't been defined. I'm not sure if that's the solution for Jest tests or just something that couldn't hurt.

WICG/inert#122

@SimenB
Copy link
Member

SimenB commented Jun 12, 2019

The Element global comes from JSDOM as mentioned in the OP, so I think it should be reported there instead of here. If we're doing weird stuff in Jest (we've been known to), happy to reopen and fix it here!

@SimenB SimenB closed this as completed Jun 12, 2019
@SimenB
Copy link
Member

SimenB commented Jun 12, 2019

Reproduction without Jest:

const { JSDOM } = require("jsdom");

const { window } = new JSDOM("");

function polyfill() {
  Object.defineProperty(window.Element.prototype, "inert", {
    enumerable: true,
    get: function() {},
    set: function() {}
  });
}

polyfill();
polyfill();

Suboptimal that it seems the prototype leaks across tests...

@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

No branches or pull requests

3 participants