felixge / node-sandboxed-module

A sandboxed node.js module loader that lets you inject dependencies into your modules.
MIT License
342 stars 42 forks source link

Mocking module scoped variables #66

Open reggi opened 6 years ago

reggi commented 6 years ago

Is it possible to mock a module scoped variable?

Given the following file. I'd like to change the value of hello, to something else.

var hello = 'Hello Sir'

console.log(hello)

https://stackoverflow.com/questions/49478755/require-and-overwrite-module-scoped-variable-for-testing