Skip to content

allowUnmocked causes no requests to match when query is specified #490

@robinbobbitt

Description

@robinbobbitt
var nock=require('nock'),
request=require('request');

nock('https://www.google.com', 
    { allowUnmocked: true })
    .log(console.log)
    .get("/abc")
    .query({'user':'fred'})
    .reply(200, "Match!")

request('https://www.google.com/abc?user=fred', function (error, response, body) {
    if (!error && response.statusCode == 200) {
        console.log(body);
    } else{
        console.log(error ? "error: " + error : "response.statusCode: "+ response.statusCode);
    }
});

With the code above, my request does NOT match and goes to google.com.
$ node nockTest.js
response.statusCode: 404

By changing allowUnmocked to false, I get:

$ node nockTest.js
matching https://www.google.com:443?user=fred to GET https://www.google.com:443/abc with query({"user":"fred"}): true
Match!

I am able to work around this and keep allowUnmocked=true by using a filteringPath to remove the query. Is this a bug or am I missing something here? Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions