knee-cola / jest-mock-axios

Axios mock for Jest
252 stars 42 forks source link

Not all valid instance methods are supported #11

Closed kmarple1 closed 5 years ago

kmarple1 commented 6 years ago

Testing the following code:

import axios from 'axios';
import { API_ROOT } from './api.config';

const baseAPI = axios.create({
    baseURL: API_ROOT
});

export default (method, url, payload, config = {}) => {
    switch (method.toLowerCase()) {
        case 'get':
        case 'head':
        case 'delete':
        case 'options':
            return baseAPI[method](url, config);
        case 'post':
        case 'put':
        case 'patch':
            return baseAPI[method](url, payload, config);
        default:
            throw new Error('CMS: Http method not specified!');
    }
};

Tests work fine for get, delete, post and put, but fail for head, options and patch because jest-mock-axios doesn't seem to support them. I realize they're rarely used nowadays, but is it possible to add support for the sake of completeness?