问题
I have a test-setup with mocha, babel and node that is meant to test ecmascript 6 code.
Does anybody have any suggestions on how to mock away imports in the module under test?
回答1:
Imports and exports in ES2015 are part of the language itself, and are designed to be statically analysable. They therefore cannot be manipulated at runtime, and that makes dynamic mocking impossible.
I would recommend that you take a look at implementing some form of lightweight dependency injection framework, or dynamic module resolver.
SystemJS could be a good choice for you as a universal module loader.
Hope that helps!
来源:https://stackoverflow.com/questions/33088439/how-can-i-mock-an-imported-module-in-ecmascript-6