我有两个组件,我想以开玩笑的方式触发click事件。 可悲的是,当我尝试在子组件上调用触发器时,它不会被触发。当我通过浏览器单击它时,它可以很好地工作。
Cars.vue
<template>
<div class="cars">
<button-luxury class="love" :onclick="updateRecords">Submit</button-luxury>
</div>
</template>
ButtonLuxury.vue
<template>
<button @click="onclick"> </button>
</template>
<script>
export default {
name: "button-luxury",
props: {
onclick: {
type: Function,
default: null,
require:false
}
}
}
jess测试文件
import Cars from './Cars.vue'
import ButtonLuxury from './ButtonLuxury.vue'
describe('Cars.vue', () => {
it('should trigger the click on button', () => {
const wrapper = shallowMount(Cars)
wrapper.find(ButtonLuxury).trigger('click') //doesnt work
wrapper.find('.love').trigger('click') // doesnt work aswell
}
}