-
-
Notifications
You must be signed in to change notification settings - Fork 771
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
stubbing module exports with closures #1248
Comments
You need to have a way of injecting your stub to do this cleanly. Something like ...
module.exports = {
a,
b,
__injectA = function(fn){ a = fn; },
__injectB = function(fn){ b = fn; }
} Of course, since you are changing the internals of the module it will affect everything else using this module. If you want to do this without altering some kind of global state, you will need to create those functions in a closure created by some exported init function. |
Ah, that makes sense. Thank you!
…On Thu, 26 Jan 2017 at 2:33 pm, Carl-Erik Kopseng ***@***.***> wrote:
You need to have a way of injecting your stub to do this cleanly.
Something like
...
module.exports = {
a,
b,
__injectA = function(fn){ a = fn; },
__injectB = function(fn){ b = fn; }
}
Of course, since you are changing the internals of the module it will
affect everything else using this module. If you want to do this without
altering some kind of global state, you will need to create those functions
in a closure created by some exported init function.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1248 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAImTsNjkfSDrIRFQsv9Fe9JJZaX538Gks5rWK51gaJpZM4LtsJg>
.
|
Closed
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I can't seem to find a way to gracefully stub the exported
a()
here:I'm guessing this fails because b has it's own copy of a.
I can do something like this which makes the test pass but it makes me want to take a shower.
Any other options?
Cheers,
The text was updated successfully, but these errors were encountered: