-
Notifications
You must be signed in to change notification settings - Fork 244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: trigger does not work on vue components #2087
Comments
@micDropper I think this is because this was historically the case with VTU v1 (for Vue 2). As I was not around at that time I don't know if there is a specific reason that we don't support this. @freakzlike @lmiller1990 do you think this would be good idea? |
Historical context can be found in issues such as: vuejs/vue-test-utils#145 vuejs/vue-test-utils#1588 probably has the best discussion. Historically, Is there a compelling use case for manually emitting an event? It's not something a user can do. In general, I recommend causing the event to be emitted like a user, instead of emitting it manually. If we did add this, I think we'd be better to make a |
This would be used when testing components that emit events not triggered by user interaction. Perhaps they would be triggered by a timer, as in my demo, or emit events as it performs other autonomous behaviors (animation, external/internal condition becomes met, etc). In my case, it'd be useful for testing heavyweight js libraries with thin vue wrappers that emit their own events (think ag-grid, vee-validate, etc). Ag-grid emits a I agree with the preference for |
Using one |
I also like |
Describe the bug
I just kinda expected vue test utils to be able to trigger Vue component events out of the box. VueWrapper does not have a trigger implementation that works for Vue components. You have to use
$emit
on the vm instance.To Reproduce
https://stackblitz.com/edit/github-kdgtxj?file=src%2Fcomponents%2FHelloWorld.vue,src%2FApp.vue,src%2Fcomponents%2F__tests__%2FHelloWorld.spec.ts,src%2F__tests__%2FApp.spec.ts
Expected behavior
mount(VueComponent).findComponent({ name: 'VueComponent' }).trigger('vueComponentEvent')
should work like
mount(VueComponent).findComponent({ name: 'VueComponent' }).vm.$emit('vueComponentEvent')
The text was updated successfully, but these errors were encountered: