Skip to content
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

BaseWrapper.prototype.trigger has a bad implementation #1952

Closed
dima4p opened this issue Jan 19, 2022 · 3 comments
Closed

BaseWrapper.prototype.trigger has a bad implementation #1952

dima4p opened this issue Jan 19, 2022 · 3 comments

Comments

@dima4p
Copy link

dima4p commented Jan 19, 2022

Subject of the issue

The method Vue#$emit accepts the name of the event an any number of the parameters that all being sent to the function - event handler.
But in test BaseWrapper.prototype.trigger accepts only one parameter after the event name.

Steps to reproduce

in the code:

<template lang='pug'>
my-component(@my_signal="my_signal")
</template>

<script>
…
 methods: {
  my_signal(...args) {
      console.log(args)
  }
},
…
</script>

in the test:

wrapper.find(…).trigger('my_signal', 1, 2)

Expected behaviour

it should be printed [1, 2]

Actual behaviour

it is printed [1]

Possible Solution

I think it is quite clear, there must be implemented the transfer of more than one argument.

BaseWrapper.prototype.trigger = function (eventString, ...args) {
@lmiller1990
Copy link
Member

trigger is designed to work with DOM events, as opposed to custom ones. Please see the documentation.

If you'd like to activate a custom event, how about:

wrapper.vm.$emit('customEvent', 1, 2, 3)

That will work!

@dima4p
Copy link
Author

dima4p commented Jan 22, 2022

trigger is designed to work with DOM events, as opposed to custom ones. Please see the documentation.

If you'd like to activate a custom event, how about:

wrapper.vm.$emit('customEvent', 1, 2, 3)

That will work!

No, it does not. I have a component "my-component", that emits a custom event "my_signal". Please write a test for the parent component using jest that function my_signal is called with 2 parameters when my-component emits the signal.

@lmiller1990
Copy link
Member

Can you fork this repo and make a PR with your minimal failing case? That would make it easier to debug and fix the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants