Skip to content

Fix tests against axios 0.33 - #201

Merged
anttiviljami merged 1 commit into
mainfrom
fix/axios-0.33-tests
Jul 25, 2026
Merged

Fix tests against axios 0.33#201
anttiviljami merged 1 commit into
mainfrom
fix/axios-0.33-tests

Conversation

@anttiviljami

Copy link
Copy Markdown
Member

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:

TypeError: Cannot read properties of undefined (reading 'name')
  at handleRequest (node_modules/axios-mock-adapter/src/handle_request.js:78:51)

Two distinct causes, one upstream change:

  1. axios 0.33 builds utils.merge results with Object.create(null). dispatchRequest runs every request's headers through that merge, so config.headers reaches the adapter with a null prototype — and axios-mock-adapter reads config.headers.constructor.name === 'AxiosHeaders', which throws on the undefined constructor. The stack points at our runRequest line, 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.
  2. The same hardening makes mergeConfig hand back null-prototype defaults.auth and defaults.proxy. toStrictEqual compares 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) — wraps MockAdapter.prototype.adapter and, only when config.headers has 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, so AxiosHeaders detection still behaves exactly as before.
  • jest.config.ts — registers the setup file via setupFilesAfterEnv.
  • src/client.test.tstoStrictEqualtoEqual for the two prototype-sensitive defaults assertions.

Verification

npm test passes 69/69 on every matrix entry:

axios result
0.25.0 (oldest supported) 69 passed
0.30.2 69 passed
0.33.0 (latest 0.x) 69 passed
1.18.1 (^1.0.0 / latest) 69 passed

npm run lint and npm run build are 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

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>
@anttiviljami
anttiviljami merged commit aba2e2a into main Jul 25, 2026
6 checks passed
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

Successfully merging this pull request may close these issues.

1 participant