I have a simple component with unit test like below. I am trying to trigger click event on anchor but I think it does not happen because of error:
Expected mock function to have been called, but it was not called.
Component:
<template>
<a @click="fetchAll" class="icon">
<Icon class="icon" scale="2" />
</a>
</template>
<script>
export default {
methods: {
fetchAll() {}
}
}
</script>
Test:
it('should fetch all', () => {
const wrapper = shallowMount(Component, {
stubs: [ 'Icon'],
localVue
})
const fetchAll = jest.fn()
wrapper.setMethods({ fetchAll })
wrapper.find('.icon').trigger('click')
expect(fetchAll).toBeCalled()
})
What is wrong?
Aucun commentaire:
Enregistrer un commentaire