Skip to content

Commit

Permalink
Merge pull request #1521 from simov/promise-tests
Browse files Browse the repository at this point in the history
Add promise tests
  • Loading branch information
simov committed Apr 1, 2015
2 parents 2284e7d + 45623b7 commit f157a25
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -62,6 +62,7 @@
"rimraf": "~2.2.8",
"server-destroy": "~1.0.0",
"tape": "~3.0.0",
"taper": "~0.4.0"
"taper": "~0.4.0",
"bluebird": "~2.9.21"
}
}
52 changes: 52 additions & 0 deletions tests/test-promise.js
@@ -0,0 +1,52 @@
'use strict'

var http = require('http')
, request = require('../index')
, tape = require('tape')
, Promise = require('bluebird')

var s = http.createServer(function(req, res) {
res.writeHead(200, {})
res.end('ok')
})

tape('setup', function(t) {
s.listen(6767, function() {
t.end()
})
})

tape('promisify convenience method', function(t) {
var get = request.get
var p = Promise.promisify(get)
p('http://localhost:6767')
.then(function (results) {
var res = results[0]
t.equal(res.statusCode, 200)
t.end()
})
})

tape('promisify request function', function(t) {
var p = Promise.promisify(request)
p('http://localhost:6767')
.spread(function (res, body) {
t.equal(res.statusCode, 200)
t.end()
})
})

tape('promisify all methods', function(t) {
Promise.promisifyAll(request)
request.getAsync('http://localhost:6767')
.spread(function (res, body) {
t.equal(res.statusCode, 200)
t.end()
})
})

tape('cleanup', function(t) {
s.close(function() {
t.end()
})
})

0 comments on commit f157a25

Please sign in to comment.