Hi maintainers 馃憢
We鈥檙e seeing compatibility issues with axios-mock-adapter@2.1.0 when used with axios@0.32.0.
Environment
- axios-mock-adapter:
2.1.0
- axios:
0.32.0
Problem
1) Crash in handle_request.js
handle_request.js assumes config.headers.constructor.name exists:
(config.headers && config.headers.constructor.name === "AxiosHeaders")
With axios 0.32, config.headers can be a null-prototype object, so config.headers.constructor is undefined, causing:
TypeError: Cannot read properties of undefined (reading 'name')
2) Matcher misses (404/no match) for params objects
Some request params objects from axios 0.32 are null-prototype objects.
Deep equality against plain object matcher config (e.g. onGet(url, { params: { include: 'x' } })) can fail even when values are equivalent, causing unexpected no-match/404 behavior.
Minimal repro (crash)
const axios = require('axios');
const MockAdapter = require('axios-mock-adapter');
const mock = new MockAdapter(axios);
mock.onGet('/x').reply(200, { ok: true });
axios.get('/x')
.then(r => console.log(r.status))
.catch(e => console.error(e.message));
Observed: Cannot read properties of undefined (reading 'name')
Expected: 200 response from mock adapter.
Suggested fix:
Guard constructor access in handle_request.js:
config.headers &&
config.headers.constructor &&
config.headers.constructor.name === "AxiosHeaders"
Hi maintainers 馃憢
We鈥檙e seeing compatibility issues with
axios-mock-adapter@2.1.0when used withaxios@0.32.0.Environment
2.1.00.32.0Problem
1) Crash in
handle_request.jshandle_request.jsassumesconfig.headers.constructor.nameexists:With axios 0.32, config.headers can be a null-prototype object, so config.headers.constructor is undefined, causing:
TypeError: Cannot read properties of undefined (reading 'name')
2) Matcher misses (404/no match) for params objects
Some request params objects from axios 0.32 are null-prototype objects.
Deep equality against plain object matcher config (e.g. onGet(url, { params: { include: 'x' } })) can fail even when values are equivalent, causing unexpected no-match/404 behavior.
Minimal repro (crash)
Observed: Cannot read properties of undefined (reading 'name')
Expected: 200 response from mock adapter.
Suggested fix:
Guard constructor access in handle_request.js: