Description
Describe the bug
Right now if you have a child component that handles an emitted event by calling a function in the parent component, it will just fail if you don't add parenthesis to the event handler name.
To Reproduce
This doesn't work:
<MainSidebar
:menu-items="menuItems"
@expanded="handleExpanded"
/>
This works:
<MainSidebar
:menu-items="menuItems"
@expanded="(value) => handleExpanded(value)"
/>
I just found out about this unexpected behaviour by chance.
It's weird because in the Vue docs they use the non-parentheses version all over the place.
Expected behavior
This should work:
<MainSidebar
:menu-items="menuItems"
@expanded="handleExpanded"
/>
Related information:
This is with a newly created Vue 3 + Vite + TypeScript application (pnpm create vite
).
Additional context
Alternative Solutions
For now, use parenthesis on all event handlers and manually pass any data to it... :(
Add information about this issue in a very visible place on the Vue Test Utils docs (didn't find anything about it when going through the site, it should be a big yellow warning box). :)
Previous discussions
vuejs/vue-test-utils#1901
vuejs/vue-test-utils#929
https://stackoverflow.com/questions/62696939/test-on-function-call-in-vue-template-only-passes-if-the-function-is-called-with/62703070#62703070