[英]Vue.Js teting with jest error axios
I'm writing test for components which uses axios.我正在为使用 axios 的组件编写测试。 I got:
我得到:
TypeError: Cannot read property 'get' of undefined
after yarn test
. yarn test
。 I tried to import axios to my *spec.js files, but it doesn't work.我试图将 axios 导入到我的 *spec.js 文件中,但它不起作用。 What should i do to pass that tests?
我该怎么做才能通过这些测试?
You can mock axios
in your *spec.js
files:您可以在
*spec.js
文件中模拟axios
:
jest.mock('axios', () => ({
get: () => {},
}));
describe('Test.spec.js', () => {
...
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.