-
-
Notifications
You must be signed in to change notification settings - Fork 342
Testing
The enemy of testing is a reliance on dependencies (e.g. jQuery, DOM, Bootstrap) being in the global scope. It's then incumbent on the developer to make sure that files are loaded and loaded in the correct order in both the application and testing environments. ES6 modules force us to declare a module's dependencies so that the module loading layer can ensure that they are available before the module executes. They also encourage us to write "inert" modules: modules which only expose functionality, but don't actually execute anything until invocation by controlling code.
####Libraries and frameworks involved in testing:
Mocha is our testing framework. It provides the functions "define" and "it" which wrap our assertions. It provides before and after hooks to allow for setup and teardown.
Karma orchestrates the testing process. It tells webpack to build the test bundle (tests and the modules they import), then executes the tests in one of many different target environments (browsers, PhantomJS, node.js) and delivers the report.
Sinon provides mocks, stubs and spies that help isolate code for testing purposes.
Chai is an assertion library that provides different flavors of assertion (e.g. expect, assert, should). It can also mock the the browser's XMLHttpRequest. For the sake of consistency, let's use Chai's assert flavor.
Rewire is a library that allows us to easily mock/stub a modules local (un-exported) variables.