Comparing version 0.11.6 to 0.12.0
@@ -31,3 +31,3 @@ var IncomingMessage = require('http').IncomingMessage; | ||
function isStream(obj) { | ||
var is = (typeof a !== 'string') && (! Buffer.isBuffer(obj)) && (typeof obj.setEncoding == 'function'); | ||
var is = obj && (typeof a !== 'string') && (! Buffer.isBuffer(obj)) && (typeof obj.setEncoding == 'function'); | ||
return is; | ||
@@ -142,3 +142,3 @@ } | ||
}); | ||
} else if (! Buffer.isBuffer(responseBody)) { | ||
} else if (responseBody && !Buffer.isBuffer(responseBody)) { | ||
responseBody = new Buffer(responseBody); | ||
@@ -145,0 +145,0 @@ } |
@@ -122,3 +122,3 @@ var path = require('path') | ||
var matchKey = method + ' ' + proto + '://' + options.host; | ||
var matchKey = method.toUpperCase() + ' ' + proto + '://' + options.host; | ||
if ( | ||
@@ -199,2 +199,6 @@ options.port && options.host.indexOf(':') < 0 && | ||
} | ||
function head(uri, requestBody, options) { | ||
return intercept(uri, 'HEAD', requestBody, options); | ||
} | ||
@@ -298,2 +302,3 @@ function _delete(uri, requestBody, options) { | ||
, put: put | ||
, head: head | ||
, intercept: intercept | ||
@@ -300,0 +305,0 @@ , done: done |
{ "name" : "nock" | ||
, "description" : "HTTP Server mocking for Node.js" | ||
, "tags" : ["Mock", "HTTP", "testing", "isolation"] | ||
, "version" : "0.11.6" | ||
, "version" : "0.12.0" | ||
, "author" : "Pedro Teixeira <pedro.teixeira@gmail.com>" | ||
@@ -6,0 +6,0 @@ , "contributors" : |
@@ -99,3 +99,3 @@ # Nock [![Build Status](https://secure.travis-ci.org/flatiron/nock.png)](http://travis-ci.org/flatiron/nock) | ||
Nock supports any HTTP verb, and it has convenience methods for the GET, POST, PUT and DELETE HTTP verbs. | ||
Nock supports any HTTP verb, and it has convenience methods for the GET, POST, PUT, HEAD and DELETE HTTP verbs. | ||
@@ -105,3 +105,3 @@ You can intercept any HTTP verb using `.intercept(path, verb [, requestBody [, options]])`: | ||
scope('http://my.domain.com') | ||
.intercept('/path', 'HEAD') | ||
.intercept('/path', 'PATCH') | ||
.reply(304); | ||
@@ -108,0 +108,0 @@ |
@@ -110,2 +110,64 @@ var nock = require('../.') | ||
tap.test("post with empty response body", function(t) { | ||
var dataCalled = false; | ||
var scope = nock('http://www.google.com') | ||
.post('/form') | ||
.reply(201, "OK!"); | ||
var req = http.request({ | ||
host: "www.google.com" | ||
, method: 'POST' | ||
, path: '/form' | ||
, port: 80 | ||
}, function(res) { | ||
t.equal(res.statusCode, 201); | ||
res.on('end', function() { | ||
t.ok(dataCalled); | ||
scope.done(); | ||
t.end(); | ||
}); | ||
res.on('data', function(data) { | ||
dataCalled = true; | ||
t.ok(data instanceof Buffer, "data should be buffer"); | ||
t.equal(data.toString(), "OK!", "response should match"); | ||
}); | ||
}); | ||
req.end(); | ||
}); | ||
tap.test("post, lowercase", function(t) { | ||
var dataCalled = false; | ||
var scope = nock('http://www.google.com') | ||
.post('/form') | ||
.reply(200, "OK!"); | ||
var req = http.request({ | ||
host: "www.google.com" | ||
, method: 'post' | ||
, method: 'POST' | ||
, path: '/form' | ||
, port: 80 | ||
}, function(res) { | ||
t.equal(res.statusCode, 200); | ||
res.on('end', function() { | ||
t.notOk(dataCalled); | ||
scope.done(); | ||
t.end(); | ||
}); | ||
res.on('data', function(data) { | ||
dataCalled = true; | ||
t.end(); | ||
}); | ||
}); | ||
req.end(); | ||
}); | ||
tap.test("get with reply callback", function(t) { | ||
@@ -349,2 +411,26 @@ var scope = nock('http://www.google.com') | ||
tap.test("head", function(t) { | ||
var dataCalled = false; | ||
var scope = nock('http://www.google.com') | ||
.head('/form') | ||
.reply(201, "OK!"); | ||
var req = http.request({ | ||
host: "www.google.com" | ||
, method: 'HEAD' | ||
, path: '/form' | ||
, port: 80 | ||
}, function(res) { | ||
t.equal(res.statusCode, 201); | ||
res.on('end', function() { | ||
scope.done(); | ||
t.end(); | ||
}); | ||
}); | ||
req.end(); | ||
}); | ||
tap.test("body data is differentiating", function(t) { | ||
@@ -351,0 +437,0 @@ var doneCount = 0 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
64275
1869