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

Rewire throws a Type Error when overriding a const while running Jest tests #6803

Closed
Shakakai opened this issue Aug 3, 2018 · 3 comments
Closed

Comments

@Shakakai
Copy link

Shakakai commented Aug 3, 2018

🐛 Bug Report

Rewire throws a Type Error when overriding a const variable while running Jest tests.

To Reproduce

  • Create a javascript file to test with a top-level variable set as a const and a simple test function
  • Create a Jest test file, use rewire to import the above module, use rewire.set to change the const value

See my repo below for a working example.

Expected behavior

I expect the Jest test to execute succesfully in the same way the Mocha tests currently do.

Link to Repo

Github Repo with bug: https://github.com/Shakakai/jest-rewire-const-error

Run npm test

~~/v8.10.0/bin/node ~~/v8.10.0/lib/node_modules/npm/bin/npm-cli.js test --scripts-prepend-node-path=auto

> [email protected] test ~~/jest-rewire-const-error
> mocha ./test/example.mocha.js && jest example



  Show mocha works
    ✓ should add the numbers together


  1 passing (5ms)

 FAIL  test/example.jest.test.js
  ● Test suite failed to run

    TypeError: Assignment to constant variable.

      at eval (eval at __set__ (example.js:72:5), <anonymous>:1:3)
      at Function.__set__ (example.js:72:5)
      at Object.<anonymous> (test/example.jest.test.js:6:15)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.905s
Ran all test suites matching /example/i.
npm ERR! Test failed.  See above for more details.

Process finished with exit code 1
@luanmuniz
Copy link

Also having this problem. Any news here?

@rickhanlonii
Copy link
Member

Hey all - I'm not familiar with rewire but it seems like they support mocha and not jest?

If someone from the rewire team wants to diagnose and let us know what, if anything, is broken or missing in Jest then I'm happy to take a look!

@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 12, 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