A method for mocking AMD dependencies when testing JavaScript modules that are loaded with the Dojo AMD loader.
Inspired by this stackoverflow question and testr.
Open tests/spec/SpecHello.js for a demo.
StubModule.js can be loaded like any other AMD module.
When you want to stub a module:
it('this is a demo', function (done) {
var stub = {};
stubModule('path/to/module', {'path/to/dependency': stub}).then(function (StubbedModule) {
var testObject = new StubbedModule();
// tests/assertions
done();
});
});
Run bower install and npm install before running the tests. Run the tests by running grunt travis.
This will not work for the ESRI JSAPI prior to version 3.4. However, at 3.4 they turned on the dojo-undef-api has tag and it works great!