Please familiarise yourself with why we have ES6 Modules and its terminology as it going to help you to understand some of the issues we will be discussing here. The article, An Introduction To JavaScript ES6 Modules is a good place to start.
We can write perfectly functioning code, that is simple, readable and optimised. But when it comes to testing, it adds another dimension to your code and changes the way you would approach coding. Those who have developed in C#, you know why we need Interfaces and implementing it will change the way you approach writing your code.
The following issues are known pain points when it comes to testing ES6 modules:
- Named Exports
- Multiple Exports
We will use a Warehouse example, which uses Mocha, Sinon and Chai, to explore how we can rewrite the code to get them to pass the above mentioned pain points, and still have them function properly. Although the title mentions spying, the idea is that if you can Spy then you should be able to Stub and Mock.
Continue reading “Spying on ES6 modules” →