Last active
October 1, 2015 18:11
-
-
Save rdsubhas/9531839ab6f710924cb9 to your computer and use it in GitHub Desktop.
es6-mocha
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
var Promise = require('bluebird'); | |
var assert = require('assert'); | |
var request = Promise.promisifyAll(require('request')); | |
var url1='http://httpbin.org/', url2=url1, url3=url1, url4=url1; | |
describe('context', function() { | |
it('should kill callbacks', Promise.coroutine(function*() { | |
// Use destructuring since "request" returns multiple values | |
[res1] = yield request.getAsync(url1); | |
assert.equal(200, res1.statusCode); | |
// Array destructuring might not work in some node versions | |
// In that case, simply use res[0].statusCode | |
[res2] = yield request.getAsync(url2); | |
assert.equal(200, res2.statusCode); | |
[res3] = yield request.getAsync(url3); | |
assert.equal(200, res3.statusCode); | |
[res4] = yield request.getAsync(url4); | |
assert.equal(200, res4.statusCode); | |
// Yay! No more "done()" and no more callbacks | |
})); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment