如何在wrapper.vm中使用jest.spyOn?Vue3组合式API测试报错
解决Vue3
测试时调整时序,先创建spy再触发事件: ```javascript it('calls buildList when child emits mounted', async () => { const wrapper = mount(YourParentComponent); // 先创建spy const buildListSpy = jest.spyOn(wrapper.vm, 'buildList'); // 再触发事件 await wrapper.findComponent(ClientTableExpandable).vm.$emit('mounted'); expect(buildListSpy).toHaveBeenCalled(); });
内容的提问来源于stack exchange,提问作者Gabriella Tavares
相关产品推荐
相关产品推荐

