Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add promise tests #1521

Merged
merged 1 commit into from Apr 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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()
})
})