【问题标题】:Vue.Js teting with jest error axiosVue.Js 测试与开玩笑错误 axios
【发布时间】:2018-08-05 02:50:43
【问题描述】:

我正在为使用 axios 的组件编写测试。 我得到了:

TypeError: Cannot read property 'get' of undefined

之后 yarn test。 我试图将 axios 导入到我的 *spec.js 文件中,但它不起作用。 我应该怎么做才能通过这些测试?

【问题讨论】:

  • import VueAxios from 'vue-axios' import axios from 'axios' import { mount } from '@vue/test-utils' import Component from '../src/components/courses/Courses' describe('Component', () => { test('is a Vue instance', () => { const wrapper = mount(Component) expect(wrapper.isVueInstance()).toBeTruthy() }) })
  • 请用代码更新你的问题

标签: javascript testing vue.js axios jestjs


【解决方案1】:

您可以在 *spec.js 文件中模拟 axios

jest.mock('axios', () => ({
    get: () => {},
}));

describe('Test.spec.js', () => {
    ...
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-19
    • 2020-08-16
    • 1970-01-01
    • 1970-01-01
    • 2017-10-01
    • 2021-11-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多