【发布时间】:2021-12-08 22:49:36
【问题描述】:
在我的设置中,我在 onMounted 函数中执行了几个函数。在我的测试中,我想等待这些完成。我怎样才能做到这一点?
我尝试使用nextTick 和flushPromises(尽管没有任何承诺),但它们都不起作用。
下面是一些示例代码:
Vue 组件:
setup() {
const mounted = ref(false);
onMounted(() => {
mounted.value = true;
})
}
测试:
describe('TestComponent', () => {
const wrapper = shallowMount(TestComponent)
it('expects mounted to be true after mount', () => {
expect(wrapper.vm.mounted).toBe(true)
})
})
【问题讨论】:
-
你得到的错误是什么?
-
我没有收到错误。测试失败,因为运行测试时“已安装”变量仍然为假
-
如果测试失败,说明有错误。请列出来。
标签: vue.js jestjs vuejs3 vue-composition-api