我已经阅读了几篇有关如何成功监视在created()中调用的方法的文章。我最终得到了这个解决方案,但是它仍然无法正常工作。我一直收到错误消息“期望有间谍,但有功能”。是什么原因导致期望中无法识别到间谍功能?
我尝试了几种将间谍添加到包装的方法,使用了模仿属性或将其添加到方法中。在我看来,我没有设法让间谍代替包装程序中的实际方法。
describe('created()', () => {
it('should call the method', () => {
const methods = {
method: jasmine.createSpy()
};
wrapper = shallowMount(Component, {
sync: false,
propsData: {
index: dummyIndex
},
methods
});
expect(wrapper.vm.method).toHaveBeenCalled();
});
});