-
Notifications
You must be signed in to change notification settings - Fork 241
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
relaxing headers check to allow partial matching #220
Conversation
function containsHeaders(reference, target) { | ||
console.log(reference, target); | ||
if (!reference || !target) return deepEqual(reference, target); | ||
if (typeof reference !== 'object' || typeof target !== 'object') return deepEqual(reference, target); |
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.
For rear edge case if for any reason handler[2]
is not object but say a String instance('false'
) - so it would not match with headers object { 0: 'f' }
even if it's passed in real request.
@@ -66,6 +66,30 @@ axios.get('/users', { params: { searchText: 'John' } } ) | |||
}); | |||
``` | |||
|
|||
Mocking a `POST` request with specifying headers that must be present among request headers(but all extra request headers are ignored): |
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.
not sure why there was nothing on filtering by headers before
'Content-Type': 'application/x-www-form-urlencoded', | ||
'Header-test': 'test-header' | ||
}; | ||
|
||
mock.onPost('/withHeaders', undefined, headers).reply(200); | ||
mock.onPost('/withHeaders', undefined, { 'Header-test': 'test-header' }).reply(200); |
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.
so we are passing more headers than specified in mock and that should still match(so it validate both filtering by headers and that fact check is partial not strict)
This change would be very helpful. While it breaks retro-compatibility a bit it feels like a better default than the current behavior. Alternately if we really want to keep retro-compatibility, we could let the |
At this point I can't do breaking changes, however support for asymmetric matchers has been implemented in #181, which will allow you to achieve the same thing. |
Allowing mock match if request contains extra headers not specified in mock explicitly.
#219
#214