nock 2.12.0 → 2.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/scope.js +20 -9
- package/package.json +6 -1
- package/tests/test_intercept.js +17 -0
package/lib/scope.js
CHANGED
|
@@ -269,16 +269,27 @@ function startScope(basePath, options) {
|
|
|
269
269
|
|
|
270
270
|
// Only check for query string matches if this.queries is an object
|
|
271
271
|
if (_.isObject(this.queries)) {
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
272
|
+
// Make sure that you have an equal number of keys. We are
|
|
273
|
+
// looping through the passed query params and not the expected values
|
|
274
|
+
// if the user passes fewer query params than expected but all values
|
|
275
|
+
// match this will throw a false positive. Testing that the length of the
|
|
276
|
+
// passed query params is equal to the length of expected keys will prevent
|
|
277
|
+
// us from doing any value checking BEFORE we know if they have all the proper
|
|
278
|
+
// params
|
|
279
|
+
if (Object.keys(this.queries).length !== queries.length) {
|
|
280
|
+
matchQueries = false;
|
|
281
|
+
} else {
|
|
282
|
+
for (var i = 0; i < queries.length; i++) {
|
|
283
|
+
var query = queries[i].split('=');
|
|
284
|
+
|
|
285
|
+
if (query[1] === undefined || this.queries[ query[0] ] === undefined) {
|
|
286
|
+
matchQueries = false;
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
var isMatch = matchStringOrRegexp(query[1], this.queries[ query[0] ]);
|
|
291
|
+
matchQueries = matchQueries && !!isMatch;
|
|
278
292
|
}
|
|
279
|
-
|
|
280
|
-
var isMatch = matchStringOrRegexp(query[1], this.queries[ query[0] ]);
|
|
281
|
-
matchQueries = matchQueries && !!isMatch;
|
|
282
293
|
}
|
|
283
294
|
}
|
|
284
295
|
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"testing",
|
|
8
8
|
"isolation"
|
|
9
9
|
],
|
|
10
|
-
"version": "2.
|
|
10
|
+
"version": "2.13.0",
|
|
11
11
|
"author": "Pedro Teixeira <pedro.teixeira@gmail.com>",
|
|
12
12
|
"contributors": [
|
|
13
13
|
{
|
|
@@ -131,6 +131,11 @@
|
|
|
131
131
|
"name": "Keith Laban",
|
|
132
132
|
"url": "https://github.com/kelaban",
|
|
133
133
|
"email": "kelaban17@gmail.com"
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
"name": "Rui Marinho",
|
|
137
|
+
"url": "https://github.com/ruimarinho",
|
|
138
|
+
"email": "ruipmarinho@gmail.com"
|
|
134
139
|
}
|
|
135
140
|
],
|
|
136
141
|
"repository": {
|
package/tests/test_intercept.js
CHANGED
|
@@ -4099,6 +4099,23 @@ test('query() will not match when a query string is malformed', function (t) {
|
|
|
4099
4099
|
})
|
|
4100
4100
|
});
|
|
4101
4101
|
|
|
4102
|
+
test('query() will not match when a query string has fewer correct values than expected', function (t) {
|
|
4103
|
+
var scope = nock('http://google.com')
|
|
4104
|
+
.get('/')
|
|
4105
|
+
.query({
|
|
4106
|
+
num:1,
|
|
4107
|
+
bool:true,
|
|
4108
|
+
empty:null,
|
|
4109
|
+
str:'fou'
|
|
4110
|
+
})
|
|
4111
|
+
.reply(200);
|
|
4112
|
+
|
|
4113
|
+
mikealRequest('http://google.com/?num=1str=fou', function(err, res) {
|
|
4114
|
+
t.equal(err.message.trim(), 'Nock: No match for request GET http://google.com/?num=1str=fou');
|
|
4115
|
+
t.end();
|
|
4116
|
+
})
|
|
4117
|
+
});
|
|
4118
|
+
|
|
4102
4119
|
|
|
4103
4120
|
test("teardown", function(t) {
|
|
4104
4121
|
var leaks = Object.keys(global)
|