Created
April 16, 2016 05:40
-
-
Save ORESoftware/f702c3ee1564b422a5cd237fcc1b68f7 to your computer and use it in GitHub Desktop.
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
| const suman = require('suman'); | |
| const Test = suman.init(module); | |
| Test.describe('SecondExample', function(db, someval, delay, assert){ // 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