Skip to content

Commit

Permalink
Add times+optional and persist+optional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pimterry committed Oct 17, 2016
1 parent 475c7a5 commit 475d605
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/test_intercept.js
Original file line number Diff line number Diff line change
Expand Up @@ -2314,6 +2314,46 @@ test('isDone is true with optional mocks outstanding', function(t) {
t.end();
});

test('optional but persisted mocks persist, but never appear as pending', function(t) {
var scope = nock('http://example.com')
.get('/123')
.optionally()
.reply(200)
.persist();

t.deepEqual(nock.pendingMocks(), []);
var req = http.get({host: 'example.com', path: '/123'}, function(res) {
t.assert(res.statusCode === 200, "should mock first request");
t.deepEqual(nock.pendingMocks(), []);

var req = http.get({host: 'example.com', path: '/123'}, function(res) {
t.assert(res.statusCode === 200, "should mock second request");
t.deepEqual(nock.pendingMocks(), []);
t.end();
});
});
});

test('optional repeated mocks execute repeatedly, but never appear as pending', function(t) {
var scope = nock('http://example.com')
.get('/456')
.optionally()
.times(2)
.reply(200);

t.deepEqual(nock.pendingMocks(), []);
var req = http.get({host: 'example.com', path: '/456'}, function(res) {
t.assert(res.statusCode === 200, "should mock first request");
t.deepEqual(nock.pendingMocks(), []);

var req = http.get({host: 'example.com', path: '/456'}, function(res) {
t.assert(res.statusCode === 200, "should mock second request");
t.deepEqual(nock.pendingMocks(), []);
t.end();
});
});
});

test('username and password works', function(t) {
var scope = nock('http://passwordyy.com')
.get('/')
Expand Down

0 comments on commit 475d605

Please sign in to comment.