Hello Meteor Forums,
I’ve been trying to mock module dependencies with known
require Npm override packages to no avail.
I would prefer this route as opposed to using dependency injection in my modules which would require a big rewrite of most of them and changes in my coding style.
This is a list of some packages I tried:
"mock-require": "^3.0.1", "mockery": "^2.1.0", "proxyquire": "^1.8.0", "rewire": "^3.0.2", "rewiremock": "^3.4.2",
When using them either dependencies have not been mocked or the modules depended on could not be found when using relative paths while trying to mock them.
They weren’t even external dependencies just other modules I wrote which I imported to the module under test with an absolute (meteor) path similar to
import moduleDependency from '/imports/api/<moduleDependencyPath>'
When using these absolute meteor paths the mocking would never work. And when trying to use relative paths the modules depended on would not be found to be mocked.
I am aware my ES6 imports are being transformed to CommonJS modules with Babel but I don’t know how this would affect the path which has to be provided to be overridden.
I am aware that most of these packages stress that they require the path provided to be overridden has to be relative to the module under test.
Has anyone been successful in using any of these packages or similar to mock dependecies of modules they are testing with
Just fyi I am currently on version
188.8.131.52 and I don’t know if
1.6.1 would offer any benefits with Babel 7.
If anyone made it this far, thanks for reading!