-
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
Enable mocking of const #117
Conversation
The tests are failing because of the fact that older node versions don't support ES6 syntax. Is there a way to only run these added tests in node 6.x versions? |
@jhnns Could you give some input here? thx! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, awesome PR! You even added tests 👍
I'm definitely willing to merge this. However, I think we can get rid of the option. I think it makes sense to apply the transform in any case because mutating const
is actually a SyntaxError
. In this case, babel would complain anyway. What do you think?
"coverage": "istanbul cover ./node_modules/mocha/bin/_mocha" | ||
}, | ||
"dependencies": { | ||
"babel-core": "~6.26.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why you're not using the ^
operator? Personally, I prefer that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally prefer to use fixed or ~
. A package should not contain breaking changes on minor updates but it often does. I find it more secure to make it fixed or set it to patch updates. Let me know if I still need to change is :).
You're right about the option. Hadn't thought about that. I'll remove the option when I have time. |
@jhnns I removed the options. It will now always use babel to convert const to let. I had to keep the old functionality though for |
it("Should be possible to mock a const variable using __with__ syntax", function() { | ||
var ES2015Module = rewire("./ES2015Module", { | ||
convertConst: true | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you've forgotten this, but I'll clean it up, thanks :)
Awesome 👍 |
Hello, Any reason why this shouldn't work with a code written in typescript? |
This PR enables the mocking of const variables.
It uses Babel to parse the code and transform const to let variables.
It can solve the following issues: #95, #79