我一直在尝试编写一个测试来检查是否在 Vue 中的标记事件上调用了函数。我有这个组件(有点总结)
<multiselect @tag="fn"></multiselect>
import Multiselect from 'vue-multiselect'
export default {
components: {
Multiselect
},
name: "TagMultiselect",
methods: {
fn(){
console.log("test");
}
}
}
我正在尝试测试是否调用了函数fn。为此,我编写了以下测试
it('triggers the function', () => {
const wrapper = shallowMount(TagMultiselect);
const spy = jest.spyOn(TagMultiselect.methods, 'fn');
const multiselect = wrapper.findComponent(Multiselect);
multiselect.vm.$emit('tag');
expect(spy).toBeCalledTimes(1)
})
但每次我得到
接听电话数:0
我究竟做错了什么?