No match for request POST even nock successfully matched request
See original GitHub issueHow real request data looks like:
{
port: 443,
path: '/',
host: 'dynamodb.us-east-1.amazonaws.com:443',
hostname: 'dynamodb.us-east-1.amazonaws.com',
method: 'POST',
headers: {
'user-agent': 'aws-sdk-nodejs/2.2.48 darwin/v4.4.3',
'content-type': 'application/x-amz-json-1.0',
'x-amz-target': 'DynamoDB_20120810.ListTables',
'x-amz-content-sha256': '...',
'content-length': 2,
host: 'dynamodb.us-east-1.amazonaws.com',
'x-amz-date': '...',
authorization: '…'
},
body: '{}'
}
How im trying to match this request with nock:
nock('https://dynamodb.us-east-1.amazonaws.com', {
reqheaders: {
'x-amz-target': 'DynamoDB_20120810.ListTables'
}
})
.post('/', {})
.reply(503, 'The service is currently unavailable or busy.')
.log((data) => console.log(data))
From log statement, i can see that nock is able to match this request:
matching https://dynamodb.us-east-1.amazonaws.com:443 to POST https://dynamodb.us-east-1.amazonaws.com:443/: true
, but im not receiving 503, 'The service is currently unavailable or busy.'
, but error:
'Nock: No match for request POST https://dynamodb.us-east-1.amazonaws.com/ {}'
Issue Analytics
- State:
- Created 7 years ago
- Comments:19 (4 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 Headers Error: Nock: No Match For Request - ADocLib
Solvednock No match for request POST even nock successfully matched request for each request you are going to have otherwise nock will throw...
Read more >No match error when testing an Express.js controller doing ...
I had a controller requesting the same backend service but onto 2 different endpoints. My intent was to mock these calls using the...
Read more >Network Requests - Cypress Documentation
Additionally you can even stub and mock a request's response. ... No guarantee your stubbed responses match the actual data the server sends;...
Read more >Nock: HTTP Mocking and Expectations - Morioh
nock ('http://www.example.com') .post('/user', _.matches({ address: { country: 'US' } ... If no request headers are specified for mocking then Nock will ...
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
I think I ran into a similar issue. Its not clear from the documentation how to use nock when you specify the entire url in the initial nock params(In my case because the URL comes from env). If you pass ‘/’ into the post it wont match properly(first thing I tried as well) and it also fails if you dont pass anything. I found it only worked after passing a empty string.
Maybe there could be a doc update? Or maybe its specified somewhere and I just missed it…
Though it’s very late to reply on this but it will surely help the new explorers.
Just use
persist()
for this, as the docs sayHope it will help you 😄