Fix tests against axios 0.33 - #201
Merged
Merged
Conversation
axios 0.31–0.33 hardened `utils.merge` to build results with `Object.create(null)`. `dispatchRequest` runs every config through that merge, so `config.headers` reaches the adapter with a null prototype and axios-mock-adapter's `config.headers.constructor.name === 'AxiosHeaders'` check throws (same in axios-mock-adapter 2.1.0, so upgrading it does not help). The same hardening makes `mergeConfig` produce null-prototype `defaults.auth` / `defaults.proxy`, which `toStrictEqual` rejects on prototype mismatch. The library itself works fine under axios 0.33 — this was purely a test tooling incompatibility, surfacing as 30 failures in the `0.*.*` CI matrix entry. - Add a jest setup that gives axios-mock-adapter a normal-prototype copy of the headers, only when they arrive with a null prototype, leaving AxiosHeaders detection untouched on axios 1.x and 0.25/0.30 - Relax the two prototype-sensitive `toStrictEqual` assertions to `toEqual` Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Co-authored-by: Claude <noreply@anthropic.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
The
0.*.*entry in the CI matrix now resolves to axios 0.33.0 (the 0.x line picked up 0.31–0.33 prototype-pollution hardening releases), and 30 of 69 tests fail there:Two distinct causes, one upstream change:
utils.mergeresults withObject.create(null).dispatchRequestruns every request's headers through that merge, soconfig.headersreaches the adapter with a null prototype — and axios-mock-adapter readsconfig.headers.constructor.name === 'AxiosHeaders', which throws on the undefinedconstructor. The stack points at ourrunRequestline, but the fault is inside the mock adapter. axios-mock-adapter 2.1.0 has the identical check, so upgrading it does not fix this.mergeConfighand back null-prototypedefaults.authanddefaults.proxy.toStrictEqualcompares prototypes, so it fails with "serializes to the same string" even though the values are unchanged.The library itself behaves correctly under axios 0.33 — this is purely a test-tooling incompatibility.
Changes
src/__tests__/setup.ts(new) — wrapsMockAdapter.prototype.adapterand, only whenconfig.headershas a null prototype, passes the handler a config with a normal-prototype copy of the headers. axios 1.x and 0.25/0.30 take the untouched path, soAxiosHeadersdetection still behaves exactly as before.jest.config.ts— registers the setup file viasetupFilesAfterEnv.src/client.test.ts—toStrictEqual→toEqualfor the two prototype-sensitivedefaultsassertions.Verification
npm testpasses 69/69 on every matrix entry:^1.0.0/latest)npm run lintandnpm run buildare clean.Note
The shim exists to work around an axios-mock-adapter bug present in both 1.22.0 and 2.1.0; worth filing upstream if we want to drop it eventually.
🤖 Generated with Claude Code