Skip to content

Instantly share code, notes, and snippets.

@wookiehangover
Last active December 24, 2015 09:49
Show Gist options
  • Save wookiehangover/6780202 to your computer and use it in GitHub Desktop.
Save wookiehangover/6780202 to your computer and use it in GitHub Desktop.
Testing with Squire
var Squire = require('squire');
var injector = new Squire();
function stubDependencies(deps){
if( !(deps && deps.forEach) ){
throw new TypeError('I need an Array!');
}
var stubbedDeps = {};
deps.forEach(function(dep){
var stub = sinon.stub();
function StubConstructor(){
return stub;
}
StubConstructor.stub = stub;
stubbedDeps[dep]= StubConstructor;
});
return stubbedDeps;
};
describe('test suite', function(){
before(function(done){
var self = this;
// Stub out all of the module dependencies to prevent side-effects
this.deps = stubDependencies([
'models/user',
'collections/calendars',
'views/settings'
]);
injector.mock(this.deps)
.require(['app'], function(mockedApp){
self.app = mockedApp;
done();
});
});
after(function(){
injector.clean();
});
it('should pass app.config to the Calendars collection', function(){
var stub = this.deps['collections/calendars'].stub;
var params = {
config: this.app.config
};
assert.ok( stub.calledWith(params) );
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment