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

Does not find matcher when missing automatically injected 'Accept' header #214

Closed
buddyp450 opened this issue Aug 27, 2019 · 2 comments
Closed

Comments

@buddyp450
Copy link

Looking for design input here...

The current utils is an exact match which can lead to confusion when inserting headers on something like a POST (as I did) with 'Content-Type': 'application/json' because my matcher wouldn't match that against the automatically injected Accept header which makes it { 'Accept': 'application/json, text/plain, */*', 'Content-Type': 'application/json' }

https://github.com/ctimmerm/axios-mock-adapter/blob/master/src/utils.js#L45

@mkalam-alami
Copy link

We're having the same issue.

The injected Content-Type header brings an additional issue: for calls without parameters, it defaults to "application/x-www-form-urlencoded", while requests with bodies set "application/json;charset=utf-8".

This means currently we have two set of headers depending on the endpoint we test:

const EXPECTED_HEADERS = {
  'Accept': 'application/json, text/plain, */*',
  'Authorization': `Bearer ${TOKEN}`,
  'Content-Type': 'application/json;charset=utf-8'
};
const EXPECTED_HEADERS_NO_BODY = {
  ...EXPECTED_HEADERS,
  'Content-Type': 'application/x-www-form-urlencoded'
};

PR #220 would be much welcome.

@ctimmerm
Copy link
Owner

Doing asymmetric matches has been merged in #181.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants