Last active
December 24, 2015 09:49
-
-
Save wookiehangover/6780202 to your computer and use it in GitHub Desktop.
Testing with Squire
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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