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?
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With