-
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
type error when rewire'ing const #196
Comments
You can see this in a unit test on the main branch by:
it("should be possible to re-assign const required methods", function () {
var test = rewire("./constModule.js");
test.__set__({meh: () => {return "bleh"; }});
const val = test.meh();
expect(val).to.be("bleh");
}); |
I have an interesting finding. If you rewire a js module below, a type error will be thrown saying the constant variable cannot be assigned.
However, a slight change will make the error disappear.
I haven't checked the rewire source yet and have no idea which behaviour is correct. But it seems that the keyword |
@georgezlei + 1 on this, found this out today too. I think the latter is incorrect, becasue it means tests will pass gracefully if you accidently re-assign a const. |
Disagree with the conclusion. The constant re-assignment can be easily detected by the lint tool and it doesn't have to be the responsibility of the unit test. On the other hand, enabling constant re-assignment can help to mock the dependencies of the target module. Think of the below example in your target module: const dep = require('dependency'); |
I'm still seeing #144 which has been closed
I'm still seeing this in rewire v6 / jest v27.4.5.
db.js
constMod.js
constMod.test.js
Output:
The text was updated successfully, but these errors were encountered: