Skip to content

How to access request headers when mocking? #1185

Answered by p16
suneettipirneni asked this question in Q&A
Discussion options

You must be logged in to vote

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

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 intercept function

all [
  {
    method: 'POST',
    headers: { 'X-TOKEN-SECRET': 'SuperSecretToken' },
    body: '{"recepient":"1234567890","amount":"100"}',
    origin: 'http:/…

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@suneettipirneni
Comment options

@p16
Comment options

@p16
Comment options

@p16
Comment options

Answer selected by suneettipirneni
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants