question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.query() with .get() causes Nock to fail with "No match for request" error

See original GitHub issue

When 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:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ivrtariccommented, Oct 18, 2018

Huh. It turns out that the nocked response matches (works correctly) when I add encodedQueryParams configuration parameter to the response setup.

0reactions
lock[bot]commented, Nov 7, 2018

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found