Skip to content

Instantly share code, notes, and snippets.

@bguiz
Last active January 12, 2016 05:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bguiz/e38bd8f32388a2a60166 to your computer and use it in GitHub Desktop.
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)
'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