Open gazzer82 opened 6 years ago
What test runner are you using? I found you can't override const
with Rewire in Jest. Change your constants to let
and see if that works. Also see https://github.com/jhnns/rewire/issues/144 and https://github.com/facebook/jest/issues/6803
Variables declared with const
cannot be overridden. You have to use var
or let
if you must rewire your variables.
Trying to write a unit test for an imported function using Chai and rewire and am struggling to be able to override some const set in that file.
So here's my test file.
Importing the file, and then setting some new values, then accessing the function I need to test via rewire get as it's not exported.
Problem is the const values I'm trying to change don't get changed when I call the function.
Here is them being declared in the global scope of the imported file, and the function I am calling which uses them:
Not really sure what's going on here. I have also set them to hard-coded values rather than environmental variables, but that doesn't seem to make any difference.
Any help most appreciated!
Thanks
Gareth