Nock: No match for request
11,488
Solution 1
Just add flag in scope { allowUnmocked: true }
nock('https://host.com', { allowUnmocked: true })
.post(`/path`)
.reply(200, {answer: "any"});
Solution 2
This happens when a nock matching the URL being hit is not found. The url being hit is
https://myshop.app.com/admin/products.json?collection_id=201&limit=10&fields=id
as seen in the error message. The URLs you are nocking do not correspond to it.
Something like this should work.
app_url = "https://myshop.app.com/"
result = nock(app_url, {
reqheaders: {
"content-type": "application/json",
}
})
.get('/admin/products.json?collection_id=201&limit=10&fields=id').
.reply(200, {
"products": [{
"id": 101
}, {
"id": 102
}, ]
});
More details about the exact way to nock can be found in the Nock Documentation.
Author by
user269867
Updated on June 28, 2022Comments
-
user269867 almost 2 years
My nock call looks like as below
app_url='myshop.app.com' result = nock(app_url, { reqheaders: { "content-type": "application/json", 'authorization': 'Basic Auth' } }) .get('/admin/products.json?collection_id=10001&limit=250&fields=id') .reply(200, { "products": [ { "id": 101}, {"id": 102}, ] });
Resolve :
(node:1378) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Nock: No match for request { .
But now,
==========updated=============
I have updated my call which is not throwing an error but now it is not intercepting the request....It is still hitting shopify to fetch the data
-
Rohit Varghese Sebastian over 6 years@user269867 Thats bad. Just noticed the trailing ',' in the products array, not sure if that creates issues.
-
Rohit Varghese Sebastian over 6 years@user269867 Any luck with the , removal ?
-
user269867 over 6 yearsNo, I changed some config not ","
-
Rohit Varghese Sebastian over 6 years@user269867 Can you elaborate the config change that you made for it to work ?
-
DoArNa almost 5 yearsThis is not working and also no information of what you changed to make it work!!
-
LEMUEL ADANE over 4 yearsThis is not right, it should be the other way around. You should not allow unmocked URL.