require-intercept
A way of intercepting required Node.js module dependencies.
Installation
via npm
npm install require-intercept
Usage
./TestModule.js
const dependency = ; moduleexports = { return dependency; } async { return { ; }; }
./TestDependency.js
moduleexports = "dependencyType": "Real"
main.js
const requireIntercept = ;const module: TestModule mockDependency stopMocking mockAround = ; const testModule = ;console;// Before any mocking it calls the real TestDependency > { "dependencyType": "Real" } const mock = "dependencyType": "Mocked" ; ; console;// Once mocked we have injected the mock without modifying the code structure > { "dependencyType": "Mocked" } ; console;// Once we have stopped mocking we restore the original module > { "dependencyType": "Real" } ; console;// And they are automatically restored afterwards > { "dependencyType": "Real" } ;
Versioning
This library uses the Semver versioning system. The numbers do not relate to maturity but the number of breaking changes introduced.