fix: Unable to access response headers when using axios 1.x with jest #5017 #5036
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.
When axios 1.0.0 runs under jest, it fails to set headers on the response object properly.
For a detailed description please see here: #5017
The problem in the plainObject check function, where
prototype === null || prototype === Object.prototype;
Is false for response.headers under jest, as jest seems to modify prototype of objects.
The fix is inspired by the is plain module https://github.com/sindresorhus/is-plain-obj, mainly their checking logic:
https://github.com/sindresorhus/is-plain-obj/blob/68e8cc77bb1bbd0bf7d629d3574b6ca70289b2cc/index.js#L7
Edit: I do now know how to write a test for this, as it manifests only under a different test framework than the project uses.