Closed minrwhite closed 8 years ago
The whole point of focusing on modules is to eliminate side effects where possible since they're so hard to test. Allowing users to override code instead of just the module exports themselves would not be in the spirit of proxyquire and would add a bunch of complexity.
Currently as far as I can tell, there is no way to mock side-effects in the initialization code of proxied modules. Example:
requiredmodule.js
testedmodule.js
testedmodule-test.js
Initially I was considering making a pull request to allow a replacement module to be specified as a string, but I saw that the tests explicitly handle the case where a module is a string so in order to simulate initialization code, I propose a
@initialization
property in a similar vein to@noCallThru
that would allow one to specify code that would be run as if at the point of the initial require.Thoughts? If this is seen as valuable effort, I'm happy to start work on a PR for this.