Javascript 摩卡咖啡与Vue:分辨率方法过度指定
这是我的测试:Javascript 摩卡咖啡与Vue:分辨率方法过度指定,javascript,unit-testing,vuejs2,mocha.js,vue-resource,Javascript,Unit Testing,Vuejs2,Mocha.js,Vue Resource,这是我的测试: describe('Documentation Component', () => { it('renders a vue instance', (done) => { expect(shallow(Documentation).isVueInstance()).toBe(true) done() }) it('Gets documentation', async (done) => { let wrapper = shal
describe('Documentation Component', () => {
it('renders a vue instance', (done) => {
expect(shallow(Documentation).isVueInstance()).toBe(true)
done()
})
it('Gets documentation', async (done) => {
let wrapper = shallow(Documentation)
await flushPromises()
expect(wrapper.vm.$data.documentation).toBe('')
done()
})
})
我遵循了Vue.js文档中的指南,但我无法实现这一点。我需要等待医生的承诺:
mounted () {
// --------------------------------------
this.$http.get(Config.urls.documentation).then(
(response) => {
this.documentation = response.body
},
(errorResponse) => {
EventBridge.$emit('request.error', errorResponse)
this.documentation = ''
}
)
}
问题是,如果我使用“done”函数给出了这个错误,如果没有它,它给出了这个错误:
Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called;
我不确定我需要做什么,只是按照文件做了(使用
async
或done
参数,不要同时使用两者
由于您已经在调用done()
,因此应该删除async
。因此此行:
it('Gets documentation', async (done) => {
应该是:
it('Gets documentation', (done) => {
如果要等待承诺,请使用另一种选择。删除
done
并仅使用async
:
it('Gets documentation', async () => {
let wrapper = shallow(Documentation)
await flushPromises()
expect(wrapper.vm.$data.documentation).toBe('')
})
问题是我需要等待承诺完成。还有另一种方法吗?它不起作用:(测试冻结。无论如何,我设法用不同的方法来修复它,而不是挂载并发送回调。我想我会重新编写其余的代码,使其更“可测试”谢谢你的时间:DIt冻结和超时?是的,我不确定会发生什么。我对这个测试东西有点陌生。我的意思是,如果你出现超时错误,我们可以尝试通过增加超时时间来补救。