-
-
Notifications
You must be signed in to change notification settings - Fork 733
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: Fix .matchHeader()
with allowUnmocked
#1480
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d2f41e5
Make header filters more robust
ww-daniel-mora 6471ec7
Update interceptor.js
ww-daniel-mora 70da46a
Safely check for header array as well as getHeader method
a1eda82
Switch to normalize options instead of checking for different possibi…
c068380
Update header checks to be more robust without adding a function to t…
307b594
Update interceptor.js
ww-daniel-mora 147be10
Match headers in match(), not matchIndependentOfBody()
paulmelnikow 499a9d7
Merge branch 'beta' into patch-2
paulmelnikow 5e0dc68
Wet the slightest bit to remove indirection
paulmelnikow 181e9e9
Remove unreachable code and move helper just preceding function that …
paulmelnikow 7a98cef
Rename matchIndependentOfBody to matchAddress to better convey its in…
paulmelnikow 1a68c69
Inline and tighten up the diff
paulmelnikow 2876c96
Fix typo; use a verbose and consistent name
paulmelnikow File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,6 +118,21 @@ test('match header on scope with function: matches when match accepted', async t | |
scope.done() | ||
}) | ||
|
||
test('match header on scope with function and allow unmocked: matches when match accepted', async t => { | ||
const scope = nock('http://example.test', { allowUnmocked: true }) | ||
.get('/') | ||
.matchHeader('x-my-headers', val => true) | ||
.reply(200, 'Hello World!') | ||
|
||
const { statusCode, body } = await got('http://example.test/', { | ||
headers: { 'X-My-Headers': 456 }, | ||
}) | ||
|
||
t.equal(statusCode, 200) | ||
t.equal(body, 'Hello World!') | ||
scope.done() | ||
}) | ||
|
||
test('match header on scope with function: does not match when match declined', async t => { | ||
nock('http://example.test') | ||
.get('/') | ||
|
@@ -192,6 +207,23 @@ test('match header on interceptor with function: matches when match accepted', a | |
scope.done() | ||
}) | ||
|
||
test('match header on interceptor with function: matches when match accepted', async t => { | ||
const scope = nock('http://example.test', { allowUnmocked: true }) | ||
.matchHeader('x-my-headers', val => true) | ||
// `.matchHeader()` is called on the interceptor. It precedes the call to | ||
// `.get()`. | ||
.get('/') | ||
.reply(200, 'Hello World!') | ||
|
||
const { statusCode, body } = await got('http://example.test/', { | ||
headers: { 'X-My-Headers': 456 }, | ||
}) | ||
|
||
t.equal(statusCode, 200) | ||
t.equal(body, 'Hello World!') | ||
scope.done() | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
test('match header on interceptor with function: does not match when match declined', async t => { | ||
nock('http://example.test') | ||
.matchHeader('x-my-headers', val => false) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍