1: 首先我自己找了很多网址看了,都没生效,官网也看了,好像还是不行
2: 我的问题是如何模拟异步
3: 项目使用vue-cli3 搭建,自带test模块
req.js 封装了axios,在发送之前做了一些参数处理
export default function req () {
// ...
axios.post()
}
table.vue 调用fetch方法,获取异步数据
<template>...</template>
<script>
import req from '@/utils/req'
export default {
methods: {
fetch () {
// ...一些操作
req(data).then(() => {
// ...一些操作
})
}
}
}
</script>
补充测试代码
jest.mock('@/utils/req')
// 省略wrapper = mount(vue)
it('## fetch data success', (done) => {
wrapper.vm.fetch()
wrapper.vm.$nextTick(() => {
expect(wrapper.vm.cloneConfig).toEqual(mockData)
done()
})
})
那你需要mock axios才行