question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Possible to rewire anonymous function

See original GitHub issue

Is 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:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
JasonSomecommented, Feb 25, 2020

Anyway, thanks for your kind help. I found one way to correct my issue: get all those to-be-mocked requires outside of the function in files using it, so now I can rewire them anyways without rewiring the original module.exports default function.

0reactions
rensbaardmancommented, Feb 24, 2020

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 😉

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found