-
Notifications
You must be signed in to change notification settings - Fork 19
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
Strict mocking isn't working as expected #171
Comments
For the first issue, in order to support "short-hand" default exports, esmock does currently apply the mock definition object as named and default exports. Maybe this behaviour should be disabled for strict mode, when the mock definition is an object. For the second issue, this is the intended behaviour,
|
Thanks for the quick response. I had noticed the short-hand default imports that you mentioned, but I can't really say what would be the right approach here. It's a pretty useful feature for both strict and partial modes, and I'm not sure it would be easy to distinguish between a short-hand mock and one that's just missing the default value. For the second issue, any chance I can convince you to change the behavior of strict mode so that it doesn't import anything that isn't explicitly defined in the mock definition? Or maybe add a stricter version that does this? |
We could update esmock to use the "very strict" behaviour described in point 2. If we do this, my preference is to introduce a new mode for this like "esmock.strictest". Do you think these would be OK @gmahomarf?
|
|
@gmahomarf if an imported module is not mocked for the strictest import tree, which outcome do you prefer?
The third case provides a clear error message, but would require ALL imported modules to be mocked at the parent. The second case would only require imported modules to be mocked when they are actually used by the parent in the test. Let's use the one you think is best and, in the meantime, get a PR ready using maybe the third option and we'll update it however you want. |
@gmahomarf to support the first option completely, named exports at the child module would need to be defined by esmock so as to support Supporting the second and third option above is preferred because those are simpler and require fewer additions. |
@tripodsan @aladdin-add feel free to ignore this of course but if you have an opinion on either of these it would be great to know what you think. |
If I'm not mistaken, options one and two already happen in strict mode (you can see option two in action in my gist, the test under 'named export missing') For strictest, I'm leaning towards option 3. It makes the most sense to me. |
@gmahomarf cool 👍 if the PR looks good to you and if you want it published now we could do that, otherwise we could wait a day or so and maybe get review from @tripodsan |
I'm in no hurry. EDIT: PR looks good |
I've noticed two problems with strict mocking:
esmock
in strict mode on a dependent module and I don't define adefault
export for the mocked dependency, I expectesmock
to fail due to the missing default export. What actually happens is that it sets the entire mock definition object to the value of the default export.esmock
in strict mode on a module and I don't include a mock of one of its dependencies, I expectesmock
to fail due to trying to import a missing dependency. What actually happens is that the original module is imported, and production code is executed (I would expect this behavior in partial mocking)I've made an example gist: https://gist.github.com/gmahomarf/c60e05ef57c35aad8e18590df8e3f945
The text was updated successfully, but these errors were encountered: