How to access request headers when mocking? #1185
Answered
by
p16
suneettipirneni
asked this question in
Q&A
-
Nock has a functionality where you can provide a function to access the request data like so: .reply(200, function handler() {
return { example: this.req.headers.example };
}) However I'm not sure how do the same thing with undici mocking. I've looked at the docs, but still no luck. Any assistance would be greatly appreciated. |
Beta Was this translation helpful? Give feedback.
Answered by
p16
May 20, 2022
Replies: 1 comment 4 replies
-
Hi @suneettipirneni , mockPool.intercept({
path: '/bank-transfer',
method: 'POST',
headers: {
'X-TOKEN-SECRET': 'SuperSecretToken',
},
body: JSON.stringify({
recepient: '1234567890',
amount: '100'
})
}).reply(200, (...all) => {
console.log('all', all)
return {
message: 'transaction processed'
}
}) the argument of that function will be the options given to the
is that what you were after? |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
suneettipirneni
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @suneettipirneni ,
this seems to be already supported.
if you try the example in the doc and add a function instead of an object in the
reply
the argument of that function will be the options given to the
intercept
function