Last active
January 12, 2016 05:25
-
-
Save bguiz/e38bd8f32388a2a60166 to your computer and use it in GitHub Desktop.
Proving that mocha executes async tests in sequence (and also shows how to use with generator functions)
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
'use strict'; | |
let co = require('co'); | |
let chai = require('chai'); | |
let expect = chai.expect; | |
function waitFor(duration) { | |
return new Promise(function(resolve) { | |
setTimeout(resolve, duration); | |
}); | |
} | |
describe.only('[mocha async test sequence]', function() { | |
let sequence = 0; | |
it('should run this #1', function() { | |
return co(function *() { | |
yield waitFor(1000); | |
expect(sequence).to.equal(0); | |
++sequence; | |
}); | |
}); | |
it('should run this #2', function() { | |
return co(function *() { | |
yield waitFor(500); | |
expect(sequence).to.equal(1); | |
++sequence; | |
}); | |
}); | |
it('should run this #3', function() { | |
return co(function *() { | |
yield waitFor(250); | |
expect(sequence).to.equal(2); | |
++sequence; | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment