@@ -263,35 +263,40 @@ Interceptor.prototype.match = function match(options, body, hostNameOnly) {
263263
264264 // Only check for query string matches if this.queries is an object
265265 if ( _ . isObject ( this . queries ) ) {
266- // Make sure that you have an equal number of keys. We are
267- // looping through the passed query params and not the expected values
268- // if the user passes fewer query params than expected but all values
269- // match this will throw a false positive. Testing that the length of the
270- // passed query params is equal to the length of expected keys will prevent
271- // us from doing any value checking BEFORE we know if they have all the proper
272- // params
273- debug ( 'this.queries: %j' , this . queries ) ;
274- debug ( 'queries: %j' , queries ) ;
275- if ( _ . size ( this . queries ) !== _ . size ( queries ) ) {
276- matchQueries = false ;
277- } else {
278- var self = this ;
279- _ . forOwn ( queries , function matchOneKeyVal ( val , key ) {
280- var expVal = self . queries [ key ] ;
281- var isMatch = true ;
282- if ( val === undefined || expVal === undefined ) {
266+
267+ if ( _ . isFunction ( this . queries ) ) {
268+ matchQueries = this . queries ( queries ) ;
269+ } else {
270+ // Make sure that you have an equal number of keys. We are
271+ // looping through the passed query params and not the expected values
272+ // if the user passes fewer query params than expected but all values
273+ // match this will throw a false positive. Testing that the length of the
274+ // passed query params is equal to the length of expected keys will prevent
275+ // us from doing any value checking BEFORE we know if they have all the proper
276+ // params
277+ debug ( 'this.queries: %j' , this . queries ) ;
278+ debug ( 'queries: %j' , queries ) ;
279+ if ( _ . size ( this . queries ) !== _ . size ( queries ) ) {
280+ matchQueries = false ;
281+ } else {
282+ var self = this ;
283+ _ . forOwn ( queries , function matchOneKeyVal ( val , key ) {
284+ var expVal = self . queries [ key ] ;
285+ var isMatch = true ;
286+ if ( val === undefined || expVal === undefined ) {
283287 isMatch = false ;
284288 } else if ( expVal instanceof RegExp ) {
285- isMatch = common . matchStringOrRegexp ( val , expVal ) ;
289+ isMatch = common . matchStringOrRegexp ( val , expVal ) ;
286290 } else if ( _ . isArray ( expVal ) || _ . isObject ( expVal ) ) {
287- isMatch = _ . isEqual ( val , expVal ) ;
291+ isMatch = _ . isEqual ( val , expVal ) ;
288292 } else {
289- isMatch = common . matchStringOrRegexp ( val , expVal ) ;
293+ isMatch = common . matchStringOrRegexp ( val , expVal ) ;
290294 }
291- matchQueries = matchQueries && ! ! isMatch ;
295+ matchQueries = matchQueries && ! ! isMatch ;
292296 } ) ;
297+ }
298+ debug ( 'matchQueries: %j' , matchQueries ) ;
293299 }
294- debug ( 'matchQueries: %j' , matchQueries ) ;
295300 }
296301
297302 // Remove the query string from the path
@@ -397,6 +402,11 @@ Interceptor.prototype.query = function query(queries) {
397402 this . queries = queries ;
398403 }
399404
405+ if ( _ . isFunction ( queries ) ) {
406+ this . queries = queries ;
407+ return this ;
408+ }
409+
400410 for ( var q in queries ) {
401411 if ( _ . isUndefined ( this . queries [ q ] ) ) {
402412 var value = queries [ q ] ;
0 commit comments