ctimmerm / axios-mock-adapter

Axios adapter that allows to easily mock requests
MIT License
3.47k stars 245 forks source link

adapter no run #386

Open crazyair opened 3 months ago

crazyair commented 3 months ago
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';

const instance = axios.create({
    adapter: config => {
        console.log('no run');
        return axios({ ...config, adapter: undefined });
    },
});

const mock = new MockAdapter(instance);

mock.onGet('/users').reply(config => {
    return new Promise(resolve => {
        setTimeout(() => {
            resolve([200, { timeout: config.timeout }]);
        }, config.timeout);
    });
});

instance.get('/users').then(data => {
    console.log('data', data);
});
marcbachmann commented 3 months ago

What's the question here? console.log('no run'); isn't logged. The adapter never gets called as it gets mocked with new MockAdapter(instance)