我只是想查明在存储操作之后是否调用了组件方法,但我收到了这个错误:
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 实例。
最佳答案
关于javascript - 如何模拟组件方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55744295/