Skip to content

Commit

Permalink
allowUnmocked causes no requests to match when query is specified (#955)
Browse files Browse the repository at this point in the history
Fix #490
  • Loading branch information
n30n0v authored and paulmelnikow committed Oct 20, 2017
1 parent ea2fe9f commit 4772df5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/interceptor.js
Expand Up @@ -339,6 +339,8 @@ Interceptor.prototype.matchIndependentOfBody = function matchIndependentOfBody(o
, path = options.path
, proto = options.proto;

path = path.split('?')[0];

if (this.scope.transformPathFunction) {
path = this.scope.transformPathFunction(path);
}
Expand Down
28 changes: 27 additions & 1 deletion tests/test_intercept.js
Expand Up @@ -5098,7 +5098,7 @@ test('match multiple paths to domain using regexp with allowUnmocked (#835)', fu
.reply(200, imgResponse);

var scope2 = nock(/google/, nockOpts)
.get(/search\?/)
.get(/search/)
.reply(200, searchResponse);


Expand Down Expand Up @@ -5171,6 +5171,32 @@ test('multiple interceptors override headers from unrelated request', function (
});
});

test('match when query is specified with allowUnmocked (#490)', function (t) {
nock.cleanAll();

var nockOpts = { allowUnmocked: true };
var searchResponse = 'Matched body';

var scope = nock('http://www.google.com/', nockOpts)
.get('/search')
.query({q: 'js'})
.reply(200, searchResponse);


mikealRequest.get('http://www.google.com', function (err, res, body) {
t.type(err, 'null');
t.equal(res.statusCode, 200);

mikealRequest.get('http://www.google.com/search?q=js', function (err, res, body) {
scope.done();
t.type(err, 'null');
t.equal(res.statusCode, 200);
t.equal(body, searchResponse);
t.end();
});
});
});

test("teardown", function(t) {
var leaks = Object.keys(global)
.splice(globalCount, Number.MAX_VALUE);
Expand Down

0 comments on commit 4772df5

Please sign in to comment.