Comparing version 0.21.0 to 0.22.0
@@ -185,3 +185,15 @@ var path = require('path') | ||
} | ||
function once() { | ||
return this.times(1); | ||
} | ||
function twice() { | ||
return this.times(2); | ||
} | ||
function thrice() { | ||
return this.times(3); | ||
} | ||
var interceptor = { | ||
@@ -199,2 +211,5 @@ _key: key | ||
, times: times | ||
, once: once | ||
, twice: twice | ||
, thrice: thrice | ||
}; | ||
@@ -201,0 +216,0 @@ |
{ "name" : "nock" | ||
, "description" : "HTTP Server mocking for Node.js" | ||
, "tags" : ["Mock", "HTTP", "testing", "isolation"] | ||
, "version" : "0.21.0" | ||
, "version" : "0.22.0" | ||
, "author" : "Pedro Teixeira <pedro.teixeira@gmail.com>" | ||
@@ -6,0 +6,0 @@ , "contributors" : |
@@ -152,9 +152,19 @@ # Nock [](http://travis-ci.org/flatiron/nock) | ||
```js | ||
nock('http://zombo.com').get('/').times(2).reply(200, 'Ok'); | ||
nock('http://zombo.com').get('/').times(4).reply(200, 'Ok'); | ||
http.get('http://zombo.com/'); // respond body "Ok" | ||
http.get('http://zombo.com/'); // respond body "Ok" | ||
http.get('http://zombo.com/'); // respond body "Ok" | ||
http.get('http://zombo.com/'); // respond body "Ok" | ||
http.get('http://zombo.com/'); // respond with zombo.com result | ||
``` | ||
Sugar sintaxe | ||
```js | ||
nock('http://zombo.com').get('/').once().reply(200, 'Ok'); | ||
nock('http://zombo.com').get('/').twice().reply(200, 'Ok'); | ||
nock('http://zombo.com').get('/').thrice().reply(200, 'Ok'); | ||
``` | ||
## Chaining | ||
@@ -161,0 +171,0 @@ |
@@ -1859,3 +1859,3 @@ var nock = require('../.') | ||
test('repeating response 2 times', function(t) { | ||
test('repeating once', function(t) { | ||
nock.disableNetConnect(); | ||
@@ -1865,12 +1865,28 @@ | ||
.get('/') | ||
.times(2) | ||
.once() | ||
.reply(200, "Hello World!"); | ||
http.get('http://zombo.com', function(res) { | ||
t.equal(200, res.statusCode, 'first request'); | ||
}); | ||
nock.cleanAll() | ||
t.end(); | ||
http.get('http://zombo.com', function(res) { | ||
t.equal(200, res.statusCode, 'second request'); | ||
}); | ||
nock.enableNetConnect(); | ||
}); | ||
test('repeating twice', function(t) { | ||
nock.disableNetConnect(); | ||
var _mock = nock('http://zombo.com') | ||
.get('/') | ||
.twice() | ||
.reply(200, "Hello World!"); | ||
for (var i=0; i < 2; i++) { | ||
http.get('http://zombo.com', function(res) { | ||
t.equal(200, res.statusCode, 'first request'); | ||
}); | ||
}; | ||
@@ -1882,1 +1898,41 @@ nock.cleanAll() | ||
}); | ||
test('repeating thrice', function(t) { | ||
nock.disableNetConnect(); | ||
var _mock = nock('http://zombo.com') | ||
.get('/') | ||
.thrice() | ||
.reply(200, "Hello World!"); | ||
for (var i=0; i < 3; i++) { | ||
http.get('http://zombo.com', function(res) { | ||
t.equal(200, res.statusCode, 'first request'); | ||
}); | ||
}; | ||
nock.cleanAll() | ||
t.end(); | ||
nock.enableNetConnect(); | ||
}); | ||
test('repeating response 4 times', function(t) { | ||
nock.disableNetConnect(); | ||
var _mock = nock('http://zombo.com') | ||
.get('/') | ||
.times(4) | ||
.reply(200, "Hello World!"); | ||
for (var i=0; i < 4; i++) { | ||
http.get('http://zombo.com', function(res) { | ||
t.equal(200, res.statusCode, 'first request'); | ||
}); | ||
}; | ||
nock.cleanAll() | ||
t.end(); | ||
nock.enableNetConnect(); | ||
}); |
83776
2458
448