question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Type Error with `const`

See original GitHub issue

I face myself against a Type Error when trying to rewire a private const I already have the last version 4.0.1

I used the workaround using let but I would prefer to use const as I don’t want to change my code only for test purposes

Demo: index.js:

const myPromisifiedFunction = promisify(someFunct.ToPromisify) index.test.js:

const myModule = rewire(‘…/myModule’) const myStub = sinon.stub() const revert = myModule.set(‘myPromisifiedFunction’, myStub) And what I get when running tests is: TypeError: Assignment to constant variable. at eval (eval at set (index.js:159:5), <anonymous>:1:19) at Object.set (index.js:159:5) at Object.<anonymous> (test/index.test.js:14:48)

Thanks in advance for any help you could provide !

Edit: I’m aware of the #79 issue, I already commented on it but since it’s closed I thought it would be better to open a new one

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:11
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

14reactions
Shakakaicommented, Aug 3, 2018

I’d like to provide some additional evidence. The issue appears to happen when using the Jest testing library but not with Mocha. I created a git repo to show the issue: https://github.com/Shakakai/jest-rewire-const-error

Here’s a link to the issue in Jest: https://github.com/facebook/jest/issues/6803 I’m not sure which library is responsible.

2reactions
missmatsukocommented, May 6, 2019

I’m having the same problem, also using Jest!

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: invalid assignment to const "x" - JavaScript | MDN
The JavaScript exception "invalid assignment to const" occurs when it was attempted to alter a constant value. JavaScript const declarations ...
Read more >
Assignment to constant variable - node.js - Stack Overflow
i try to read the user input and sent it as a email. but when i run this code it gives me this...
Read more >
JavaScript TypeError - Invalid assignment to const "X"
This JavaScript exception invalid assignment to const occurs if a user tries to change a constant value. Const declarations in JavaScript can ...
Read more >
[Fixed] TypeError: Assignment to constant variable in JavaScript
TypeError: Assignment to constant variable in JavaScript occurs when we try to reassign value to const variable. If we have declared variable with...
Read more >
Errors: Invalid Const Assignment - JavaScript - W3cubDocs
TypeError: invalid assignment to const "x". The JavaScript exception "invalid assignment to const" occurs when it was attempted to alter a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found