Closed CMCDragonkai closed 6 years ago
No this will not be mocked. The only thing rewire does (at the moment), is giving you the opportunity to reassign global variables (var, let, const) of the module itself. It is also important to note that the original fs
will be loaded initially. You can replace the result of the require with a mock object using rewire __set__
or __with__
. So if the required module (eg. fs) does something on initiating, this will still be executed. If this is an issue, you'll need something like proxyquire
to prevent this.
Yes. It's only one level deep. And there are no plans to change that because I think it could be very confusing otherwise.
So the example shows the ability to rewire the
'fs
require. However if the module you're rewiring also requires/imports another module which also requiresfs
, do all transitive uses offs
get rewired to the fs mock or is it only 1 level deep?