-
Notifications
You must be signed in to change notification settings - Fork 157
Testing handlers should not require that you add parentheses #530
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
Comments
I agree this is confusing. I wonder why this isn't working? Definitely a bug, I'd say. We should fix this. Is that something you'd like to try and do? |
@lmiller1990 I'm picking this one as my first one. Is that an easy one? Can you guide me towards which files I should be looking. I've been trying to figure out but I have no clue. |
Hard to say if any of the open issues are easy/hard without trying to fix them, heh. Learning to work on a new code base is never easy - good place to start, though, this would be a great one to fix. I'd recommend trying a few templates - webpack, Jest, Vitest. Is this runner/bundler specific? Let's try to figure out if there's actually a bug here, or potentially in another part of the tool chain. Also try native events vs custom events - is it specific to one of those? Another debugging tip - try reproduce without a runner: // repro.js
require('jsdom-global')()
const { mount } = require('@vue/test-utils')
// if you need Vue
const vue = require('vue/dist/vue.common.js')
const C = {
template: `<button @click="fire" />`,
methods: {
fire() { console.log('should log') }
}
}
mount(C).find('button').trigger('click')
// should log Run with |
You minimal repro is working so it's not an issue from this repo. I'll try to see what's going on with webpack, Jest, Vitest. I'm almost 100% sure that jest fails as the project I'm working we are using 2.7 with Jest and I remember facing the same issue. |
Seems like a problem in So - if this isn't a bug here, we can move the issue to vue-jest. I'll do that now,. |
Thanks for looking into this guys 🙏 BTW the environment I observed this behaviour in was Vue 3 + Vite + Vitest. Here are some previous discussions in other repositories that might shed some light into why this is happening: Vitest: vitest-dev/vitest#2066 |
Subject of the issue
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.
Steps to reproduce
This works:
This does not work:
Expected behaviour
This should work:
Actual behaviour
This just fails and I think there isn't enough information as to why if the Vue documentation exemplifies event handling usually without parentheses.
Possible Solution
For now, use parenthesis on all event handlers.
Talk to the Vue team about it, make them change their ways/docs :P
Add this information in a very visible place on the Vue Test Utils docs.
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
The text was updated successfully, but these errors were encountered: