Event not being caught on child component?
See original GitHub issueIt seems that when I do a dispatch() on a vue-component that is a child element of the component I’m testing, the event is either not fired at all or not caught by the vue event handler.
If I replace the ui-navigation-level component with a simple div, the event is caught.
This is the component (stripped to bare functionality):
<template>
<ul class="ui-navigation">
<ui-navigation-level
:options="options"
@select="handleSelect"
></ui-navigation-level>
</ul>
</template>
<script>
import NavigationLevel from './ui-navigation-level.vue'
export default {
name: 'ui-navigation',
props: {
options: {
type: Array,
required: true,
},
},
components: {
'ui-navigation-level': NavigationLevel,
},
methods: {
handleSelect(option) {
this.$emit('select', option)
},
},
}
</script>
And the test:
it('handles the select event', () => {
const handleSelect = sinon.spy(Navigation.methods, 'handleSelect')
const wrapper = mount(Navigation, {
propsData: {
options: [
/* ... */
],
},
})
wrapper.find('.ui-navigation-level')[0].dispatch('select')
expect(handleSelect).to.be.calledOnce //Result: called 0 times
})
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Component event not being caught - Salesforce Stack Exchange
A component event will not be caught by child components and while an application event will be caught, it's very expensive and inefficient ......
Read more >Why is Vue event not being caught in parent? - Stack Overflow
I'm new to Vue and trying to get the hang of the trivial example of sending an event from a child component. I...
Read more >7. Listen to child component events - Angular and NgRx
The EventEmitter in Angular is used to emit event from child components to parent components and can pass what ever object, array primitive, ......
Read more >Component Events | Vue.js
Unlike native DOM events, component emitted events do not bubble. You can only listen to the events emitted by a direct child component....
Read more >Parent not catching events fired in child component-Vue.js
means that the root Vue is listening for the child component to emit a click event, and that doesn't appear to be your...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yup, when finding using the component object, it works!
Hmm, found the (an) issue, I think. This returns undefined:
wrapper.find('.ui-navigation-level')[0].isVueComponent
Vue components and DOM nodes are treated differently. If you use a DOM selector, it will return a vnode - not a vue instance.