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

Libraries that use Symbol properties on builtin prototypes break in Jest #4603

Closed
cowboyd opened this issue Oct 4, 2017 · 8 comments
Closed
Labels

Comments

@cowboyd
Copy link

cowboyd commented Oct 4, 2017

Do you want to request a feature or report a bug?
bug

What is the current behavior?

Libraries that add Symbols to builtins like Object.prototype and Array.prototype for unique, anonymous properties break using Jest.

If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can yarn install and yarn test.

demonstration of the problem

What is the expected behavior?

Symbol properties can be added to builtin prototypes. This works IRL in node, browser, and other testing frameworks.

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

$ node --version
v8.5.0
$ yarn test --version                                                                   ⏎
yarn test v1.0.2
$ jest "--version"
v21.2.1
✨  Done in 0.26s.
$ uname -a
Darwin 16.7.0 Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu-3789.70.16~2/RELEASE_X86_64 x86_64
@ladyleet
Copy link

ladyleet commented Oct 6, 2017

Wish it would jest work! 👯👏😂👍

@taras
Copy link

taras commented Oct 7, 2017

Jest tests run in JSDOM. JSDOM uses Node.js VM to run tests in isolation with window object. Unfortunately, modules imported by require run in original node context. So, funcadelic works as expected by the typeclass implementations are added to Node context rather than VM context.

typeclass implementations are available in Node context

typeclasses implementations are not available in test vm

I created a test-setup.js file and added it to jest with

  "jest": {
    "testRegex": "(/tests/.*|\\.(test|spec))\\.(js)$",
    "setupTestFrameworkScriptFile": "<rootDir>/test-setup.js"
  }

Inside of test-setup.js, I'm calling require but it's still running in original node's context not VM's context. The require inside of VM is a wrapper provided by jest-mock library. It seems that this library might be bound incorrectly to node instance rather than the VM instance.

There are several related issues in Node & Jest repoes

@cowboyd
Copy link
Author

cowboyd commented Oct 9, 2017

Is there a workaround for this? I.e. to direct jest to say which modules should be run in the VM context?

@github-actions
Copy link

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Feb 26, 2022
@cowboyd
Copy link
Author

cowboyd commented Feb 28, 2022

good times!

@github-actions github-actions bot removed the Stale label Feb 28, 2022
@github-actions
Copy link

This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.

@github-actions github-actions bot added the Stale label Feb 28, 2023
@github-actions
Copy link

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 30, 2023
@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 Apr 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants