From 142fb816f5cc63c0128e65de6fb55171e94c02f4 Mon Sep 17 00:00:00 2001 From: David Tanner Date: Mon, 18 Jul 2022 10:04:41 -0600 Subject: [PATCH 1/2] fix(documentation): Add notes about Scope vs Interceptor matchHeader calls --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 8435fffe9..74b69ba8b 100644 --- a/README.md +++ b/README.md @@ -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. From 9b24e188d71254c8f5e3cd886b295270aa762d81 Mon Sep 17 00:00:00 2001 From: David Tanner Date: Mon, 18 Jul 2022 12:34:19 -0600 Subject: [PATCH 2/2] Prettier --- CONTRIBUTING.md | 2 +- README.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4280a7472..e224f83b7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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`. diff --git a/README.md b/README.md index 74b69ba8b..6d7e7f3b3 100644 --- a/README.md +++ b/README.md @@ -856,13 +856,13 @@ const scope = nock('http://api.myservice.com') // Only this interceptor will match the header value `x-my-action` with `MyFirstAction` .matchHeader('x-my-action', 'MyFirstAction') .reply(200, { - data: 'FirstActionResponse' + 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' + data: 'SecondActionResponse', }) ```