I am looking for a way to easily create AxiosError (from the axios lib itself or an external helper)
The context.
I have this function that I want to test.
import { AxiosError } from 'axios';
export function isEmailConflict({ error }: { error: AxiosError<{ type?: string; message?: string }> }) {
// ...
}
So far I performed it in this way
import { AxiosError } from 'axios';
// ...
describe('isEmailConflict', () => {
function newConflicError(): AxiosError {
return {
isAxiosError: true,
name: '',
message: '',
toJSON: () => ({}),
config: {},
response: {
data: { type: 'aa', message: 'bb' },
status: 409,
statusText: 'Conflict',
headers: {},
config: {},
},
};
}
it('should return true if the passed error is of type email already used', () => {
const error = newConflicError();
//...
});
but I find it ugly, is there an easy way to create an AxiosError ?
I already tried ts-auto-mock but I find it too intrusive in my tests config.
