Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1521 from simov/promise-tests
Add promise tests
- Loading branch information
Showing
2 changed files
with
54 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
}) | ||
}) |