Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(documentation): Add notes about Scope vs Interceptor matchHeader calls #2382

Merged
merged 2 commits into from Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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