Created
February 14, 2016 00:18
-
-
Save ORESoftware/e3a3734d630f75400aaa to your computer and use it in GitHub Desktop.
Dependency injection with Suman
This file contains 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
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