.query() with .get() causes Nock to fail with "No match for request" error
See original GitHub issueWhen setting up the Nock response for GET request like this:
nock(TEST_PARAMS.SERVER_URL)
.log(console.log)
.persist()
.get(TEST_PARAMS.QUERY_PATH)
.query({
'q': getNamespaceQueryParameter()
})
.reply(200, TestUtils.createNamespaceResponse());
Nock reports:
matching https://instance.salesforce.com:443/services/data/v39.0/query?q=SELECT%20NamespacePrefix%20FROM%20ApexClass%20WHERE%20Name%20%3D%20%27WebServiceProvider%27 to GET https://instance.salesforce.com:443/services/data/v39.0/query with query({"q":"SELECT%20NamespacePrefix%20FROM%20ApexClass%20WHERE%20Name%20%3D%20%27WebServiceProvider%27"}): false
Error: Nock: No match for request
When rewriting the same as:
nock(TEST_PARAMS.SERVER_URL)
.log(console.log)
.persist()
.get(`${TEST_PARAMS.QUERY_PATH}?q=${getNamespaceQueryParameter()}`)
.reply(200, TestUtils.createNamespaceResponse());
the unit test passes - the request is correctly nocked and the response is correctly parsed. What gives?
Versions
Software | Version(s) |
---|---|
Nock | 9.6.1 |
Node | 8.4.0 |
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Error: Nock: No match for request - Stack Overflow
I am calling 2 apis, 1 is post and 1 is get. And doing Promise.all([1stApi, 2edApi]). But getting error as - Error: Nock:...
Read more >Nock: No match for request · Issue #1049 - GitHub
I get the following error: error: Couldn't fetch foursquare data Error: Nock: No match for request { "method": "GET", ...
Read more >Nock - JavaScripting.com
If no request headers are specified for mocking then Nock will automatically skip matching of request headers. Since the host header is a...
Read more >No match error when testing an Express.js controller doing ...
The solution was to append the call to the .persist() method between nock('http://backend') and get('/user/details') as shown in code below:
Read more >Nock: No match for request
"No match for response" when using got with error responses [Got][] automatically retries failed requests twice. That means if you have a test...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Huh. It turns out that the nocked response matches (works correctly) when I add encodedQueryParams configuration parameter to the response setup.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue and add a reference to this one if it’s related. Thank you!