Skip to content

Testing handlers should not require that you add parentheses #530

Open
@lobo-tuerto

Description

@lobo-tuerto

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:

<MainTopbar @account="handleTopbarAccountClick()" />

This does not work:

<MainTopbar @account="handleTopbarAccountClick" />

Expected behaviour

This should work:

<MainTopbar @account="handleTopbarAccountClick" />

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.

<MainTopbar @account="handleTopbarAccountClick" />

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions