TypeError: _axiosMockAdapter.MockAdapter is not a constructor

TypeError: _axiosMockAdapter.MockAdapter is not a constructor

我正在使用 vuejs、vue-testing-library、jest、axios 和 axios-mock-adapter 来测试组件。在尝试 运行 我的测试时,我立即 运行 遇到以下错误:

TypeError: _axiosMockAdapter.MockAdapter is not a constructor

我的测试:

import GlobalSearch from '../src/components/global_search.vue';
import { render, fireEvent } from '@testing-library/vue';
import { axios } from 'axios';
import { MockAdapter } from 'axios-mock-adapter';

// jest.mock("axios", () => ({
//  get: () => Promise.resolve(
//      [{
//          "content":"Keith's Company - Keith's First Project",
//          "id":3,
//          "searchable_type":"Project",
//          "url":"/projects/1"
//      }]
//  )
// }))

describe('GlobalSearch', () => {
    it('It renders its default state', async () => {
        let mock = new MockAdapter(axios);

        const { findByText, getByText } = render(GlobalSearch);

        findByText('Companies, Contacts, Projects');

        const searchResults = [{
            "content":"Keith's Company - Keith's First Project",
            "id":3,
            "searchable_type":"Project",
            "url":"/projects/1"
        }]
        mock.onGet('/search/index').reply(200, searchResults);

        await fireEvent.update(getByText('Companies, contacts, projects'), 'ke')

        getByText('First Project');
    });
});

我做错了什么?另外,这个堆栈是不是很标准?

MockAdapter 是默认导出的,所以去掉导入语句上的大括号:

import MockAdapter from 'axios-mock-adapter';

而不是:

import { MockAdapter } from 'axios-mock-adapter';