【发布时间】:2019-04-26 02:54:09
【问题描述】:
我正在尝试像这样测试组件事件:
// template: <form @submit.prevent="save"></form>
const save = jest.fn()
const wrapper = mount(MyComponent, {methods: { save }})
wrapper.find('form').trigger('submit.prevent')
expect(save).toBeCalled() // Called successfully
事件调用组件方法的地方。效果很好
但是如果我使用自定义组件,则不会调用组件方法
// template: <my-custom-form @submit="save"></my-custom-form>
const save = jest.fn()
const wrapper = mount(MyComponent, {methods: { save }, stubs: ['my-custom-form']})
wrapper.find('my-custom-form-stub').trigger('submit')
expect(save).toBeCalled() // Expected mock function to have been called, but it was not called.
如何解决?
【问题讨论】:
标签: vue.js jestjs vue-test-utils