Skip to content

Commit

Permalink
fix(README): Add notes about Scope vs Interceptor matchHeader calls (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidTanner committed Jul 19, 2022
1 parent b4974fb commit d9bab65
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Expand Up @@ -58,7 +58,7 @@ it into your editor][integrate prettier].

[integrate prettier]: https://prettier.io/docs/en/editors.html

If you don't want to integrate with your editor, you can run `npm run prettier`
If you don't want to integrate with your editor, you can run `npm run format:fix`
instead.

Semantic issues are checked with ESLint via `npm run lint`.
Expand Down
13 changes: 13 additions & 0 deletions README.md
Expand Up @@ -846,11 +846,24 @@ If you need to match requests only if certain request headers match, you can.

```js
const scope = nock('http://api.myservice.com')
// Interceptors created after here will only match when the header `accept` equals `application/json`.
.matchHeader('accept', 'application/json')
.get('/')
.reply(200, {
data: 'hello world',
})
.get('/')
// Only this interceptor will match the header value `x-my-action` with `MyFirstAction`
.matchHeader('x-my-action', 'MyFirstAction')
.reply(200, {
data: 'FirstActionResponse',
})
.get('/')
// Only this interceptor will match the header value `x-my-action` with `MySecondAction`
.matchHeader('x-my-action', 'MySecondAction')
.reply(200, {
data: 'SecondActionResponse',
})
```

You can also use a regexp for the header body.
Expand Down

0 comments on commit d9bab65

Please sign in to comment.