Possible to rewire anonymous function
See original GitHub issueIs it possible to rewire an anonymous function that is returned as module.exports
? For example, if I want to have a dep.js
file with the following content:
module.exports = function(inp) { blah }
How can I rewire it to change the module.exports (__set__ it) to another function? (it is useful to me, because I am about to stub it for testing another code file that require-s it, but anyway don’t care about why that would be useful to me)
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Possible to rewire a method inside an anonymous function?
Trying to rewire the bar() method inside an anonymous function. Is it possible? I can't see how to overwrite bar() after having tried...
Read more >Use rewire to stub function in anonymous export in NodeJS
Trying to stub (aka rewire) the bar() method inside an anonymous function. Is it possible? I can't see how to overwrite bar() after...
Read more >The Trick to Teach Anonymous Functions to 11-Year-Olds
In computer science, a anonymous function is considered a fairly advanced topic. Many computer science majors in college don't learn it ...
Read more >javascript - Self-Executing Anonymous Function vs Prototype
Self executing anonymous functions are used to automate script execution without hooking into external events (i.e. window.onload).
Read more >Testing Non-Exported Functions in JavaScript - Samantha Ming
# Introducing Rewire · inject mocks for other modules or globals like process · inspect private variables · override variables within the module....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Anyway, thanks for your kind help. I found one way to correct my issue: get all those to-be-mocked
require
s outside of the function in files using it, so now I can rewire them anyways without rewiring the originalmodule.exports
default function.Sorry, I miss what you are trying to do. If you could include a minimal example of what doesn’t work, I could take a look. Or maybe it’s just over my head 😉