Skip to content

Instantly share code, notes, and snippets.

@ORESoftware
Created February 14, 2016 00:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ORESoftware/e3a3734d630f75400aaa to your computer and use it in GitHub Desktop.
Save ORESoftware/e3a3734d630f75400aaa to your computer and use it in GitHub Desktop.
Dependency injection with Suman
const assert = require('assert');
const suman = require('suman');
const Test = suman.init(module,'suman.conf.js'); //we now utilize a suman config file which is useful for configuring reporting, IoC, etc
Test.describe('SecondExample', function(db, server, request){ // normally we only need to inject a couple of values per test, and we don't really need the dependency array
assert(server.isListening); // values are injected asynchronously, so we are already ready to go
assert(db.isConnected); // values are injected asynchronously, so we are already ready to go
var results = null;
this.before(() =>{
return Promise.all([
request.get(server.getUrl()).then(function(body){
results = body.success;
}),
db.results.find({foo:'bar'})
]); //don't need a catch here necessarily, as Suman will handle errors
});
this.describe('A nested describe', function(){
this.it('tests db result', () => {
results.forEach(function(result){
assert(result.bar); // here we check all results in one it() case,
}); // but Suman also has powerful features to help you create a dynamic number of it() test cases
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment