我有一个vue login in组件,它没有通过测试:
LoginForm should emit submit event
Error:
submit event should be emitted when submitting form
expect(jest.fn()).toHaveBeenCalled()
Expected number of calls: >= 1
Received number of calls: 0
按钮:
<button type="button" id="login-button" :disabled="!enableSubmit" @click="submit()">Submit</button>
方法:
submit() {
if(this.username != "" && this.password != "") {
this.$emit("You have successfully loged in", this.username && this.password)
} else {
console.log("Not logged in")
}
}
如何正确地发出submit事件?
1条答案
按热度按时间ztyzrc3y1#
在父组件中,可以监听子组件发出的submit事件,如下所示: