Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { JestConfigWithTsJest } from 'ts-jest'
const jestConfig: JestConfigWithTsJest = {
testEnvironment: 'node',
testMatch: ['**/?(*.)+(spec|test).ts?(x)'],
setupFilesAfterEnv: ['<rootDir>/src/__tests__/setup.ts'],
transform: {
'^.+\\.[tj]s?$': [
'ts-jest',
Expand Down
18 changes: 18 additions & 0 deletions src/__tests__/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import MockAdapter from 'axios-mock-adapter';
import type { AxiosRequestConfig } from 'axios';

/**
* axios >= 0.33 hardened its internal config/header merge to build null-prototype objects.
* axios-mock-adapter reads `config.headers.constructor.name` to detect AxiosHeaders, which
* throws on such objects. Hand the mock adapter a normal-prototype copy of the headers.
*
* @see https://github.com/ctimmerm/axios-mock-adapter/blob/master/src/handle_request.js
*/
const originalAdapter = MockAdapter.prototype.adapter;
MockAdapter.prototype.adapter = function patchedAdapter(this: MockAdapter) {
const handleRequest = originalAdapter.call(this) as (config: AxiosRequestConfig) => Promise<unknown>;
return ((config: AxiosRequestConfig) =>
config.headers && Object.getPrototypeOf(config.headers) === null
? handleRequest({ ...config, headers: { ...config.headers } })
: handleRequest(config)) as ReturnType<typeof originalAdapter>;
};
4 changes: 2 additions & 2 deletions src/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ describe('OpenAPIClientAxios', () => {
expect(d.timeout).toBe(1234);
expect(d.withCredentials).toBe(true);
expect(d.adapter).toBe(userAdapter);
expect(d.auth).toStrictEqual({
expect(d.auth).toEqual({
username: 'fake',
password: 'fakepassword'
}),
Expand All @@ -296,7 +296,7 @@ describe('OpenAPIClientAxios', () => {
expect(d.validateStatus).toBe(userValidateStatus);
expect(d.maxRedirects).toBe(99);
expect(d.socketPath).toBe('/fake/path/example');
expect(d.proxy).toStrictEqual({
expect(d.proxy).toEqual({
host: '1.2.3.4',
port: 9876,
auth: {
Expand Down
Loading