我只是想找出在执行存储操作后是否已调用组件方法,但出现此错误:
expect(jest.fn())[.not].toHaveBeenCalled()
jest.fn() value must be a mock function or spy.
Received:
function: [Function bound mockConstructor]
这是我的单元测试:
describe('MyComponent.spec.js', () => {
let methods = {
setLocation: jest.fn()
// more methods...
}
it('calls setLocation on undo/redo', () => {
let wrapper = mount(MyComponent, {
store,
localVue,
methods
})
store.dispatch('doUndo')
expect(wrapper.vm.setLocation).toHaveBeenCalled()
})
})
不确定这是否是一种好习惯,但是我正在使用实际的商店和本地Vue实例。