-
Notifications
You must be signed in to change notification settings - Fork 31
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
Please add a test for a module that returns a Class that gets newed up by the SUT #127
Comments
The request is not very clear. You are not doing anything except mocking the dependency of a SUT, and what it is - class, function, or a variable - does not matter at all. Once upon a time I've written an article where the majority of the mocking cases, including classes, have been covered - https://dev.to/thekashey/please-stop-playing-with-proxyquire-11j4 You also have a little problem with your example (no .disable), as well as you can use more compact code. - rewiremock('../../../real/code/my-real-class').with(FakeDep);
- rewiremock.enable();
- const sut = require('../../../real/code/my-sut');
you forgot to disable
+ const sut = rewiremock.proxy(() => require('../../../real/code/my-sut', {
+ '../../../real/code/my-real-class': FakeDep
+}); |
I've been wrestling with this example and have created an article outlining what I did to get it to work.
That article is available here: https://coding-art.blogspot.com/2021/03/how-to-test-nodejs-module-and-swap-out.html
I've seen many people ask for this example and I don't know of any that have received a satisfying answer.
I think that if you add this to your tests, we will be satisfied.
Thanks a lot!
(We use the pattern of a module returning a class that is later newed up quite a bit)
The text was updated successfully, but these errors were encountered: