-
Notifications
You must be signed in to change notification settings - Fork 128
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
Doesn't work with ES6 consts #79
Comments
+1 for this. My workaround was using |
Yes, that works, and is my current workaround, but I really don't want to have to open the code up to bugs in order to test it... |
Well ... re-assigning In order to do this, rewire would need to change the code (like @brenolf did manually). Therefore, we would need to use a parser which is currently out of scope. However, if we want to support ES6 modules someday, we will need a parser anyway, so I'll consider this when rewriting rewire. |
+1 for ES6 consts. Thanks to @brenolf for the workaround. |
@erbridge @brenolf dcrockwell @dcrockwell For what it's worth, proxyquire seems to work fine using ES6 consts. I've yet to write some more complex tests with it but initial results are encouraging. |
I can't reproduce this issue. |
Do you have an example? I'm pretty sure that this can not work. |
var r = rewire('./reducer');
const reduceAddAction = r.__get__('reduceAddAction'); Where But maybe you were talking about overwriting? |
Exactly |
Riffing on what @kaktus42 was saying though, you can take advantage of the way JS const works for evil and profit in the case when it's an object:
In this case you're not reassigning the variable identifier, and you're changing a referenced value, so it is possible, whether or not it's a good idea or not is another thing entirely 😄 |
I think it's totally valid to change |
+1 for allowing rewire of const's |
+1 again! |
you should check this out : https://mathiasbynens.be/notes/es6-const |
+1 yet again! |
+1 |
+1 for const and for full es6 support... |
@rewiregps You link an article that very well articulates why this cannot work. The bindings are immutable. So this already works exactly how it should. You cannot override a const binding, which is what rewire does. |
@shivarajnaidu I'm thinking about ES6 support, but it's not that easy :) – especially as long as the loader spec is not finished yet. |
Well, in my case, I needed to stub a method from a private const of a module. proxyquire supports this use case For example my-module.js
my-module-spec.js
|
Rewiring |
@jhnns 4.0.0 here, this does not work. main.js main.test.js
|
@jhnns I do have the same problem as @goyney :( The only difference I have is that it's not from destructuring. Demo:
index.test.js:
And what I get when running tests is: |
As a possible "dirty" workaround, it's possible to
|
Still having this issue even with |
Still having this issue even with rewire 6.0.0, any fixes or workarounds? |
I just had to change es6 to es5 and it worked. |
You get errors like this:
The text was updated successfully, but these errors were encountered: