Skip to content

Instantly share code, notes, and snippets.

@ORESoftware
Created February 14, 2016 00:02
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/69c52a93ea22d1a53fcd to your computer and use it in GitHub Desktop.
Save ORESoftware/69c52a93ea22d1a53fcd 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', ['delay', 'db', 'val'], function(delay, db, val){ // normally we only need to inject a couple of values per test
var results = [];
db.makeDatabaseCall().then(function(values){ // db connection is already made because it was created and injected
(values || []).filter(function(val){
return val && val.foo;
}).forEach(function(val){
results.push(val);
});
}).then(function(){
delay(); // calling this allows us to invoke the next describe callback, this allows us to effectively block so that we can register a dynamic number of test cases (if we want to)
});
this.beforeEach(t => {
t.data.the = 'clash';
});
this.beforeEach(async function(t) { //obligatory ES7 example
var ret = await val.somePromiseMaker();
return await ret.doSomeThingAsync();
});
this.describe('this does not run until after db call completes and delay is called', function(){
results.forEach(result => {
this.it('tests db result', t => {
assert(t.data.the);
});
this.it('tests db result', (t,done) => {
setTimeout(function(){
done(new Error('Passing an error to done will fail the test as it should');
},2000);
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment