Vue-test-utils: Triggering event on elements inside a slot throws an exception

Created on 27 Oct 2017  路  5Comments  路  Source: vuejs/vue-test-utils

While trying to trigger an even inside a component's slot, we encounter an exception.
Please find part of the code below.

Component

<template>
<div>
    <slot name="input">
    </slot>
</div>
</template>

Wrapper option

{
    slots: {
        input: '<input />',
    },
}

Test

wrapper.find("input").trigger("input")

The stack is not very useful

TypeError: Cannot read property '_withTask' of undefined
    at remove$2 ([...]/Input.spec.ts:11:346754)
    at updateListeners ([...]/Input.spec.ts:11:91651)
    at Array.updateDOMListeners ([...]/Input.spec.ts:11:347728)
    at patchVnode ([...]/Input.spec.ts:11:285527)
    at VueComponent.patch [as __patch__] ([...]/Input.spec.ts:11:297113)
    at VueComponent.Vue._update ([...]/Input.spec.ts:11:121921)
    at VueComponent.update ([...]/Input.spec.ts:11:1114851)
    at [...]/Input.spec.ts:11:1115051
    at Array.forEach (<anonymous>)
    at VueComponent.update ([...]/Input.spec.ts:11:1114931)
bug help wanted

Most helpful comment

I got the same error using the render function.
After debugging, I saw that this occur when they are an an undefined event or an nullable event in the component:

export default {
  render (createElement) {
    return createElement('input', {
      on: {
        input: null,
        change: undefined
      }
    })
  }
}

Hope this will help to fix the issue

All 5 comments

Thanks for the bug report.

I can't reproduce this using the code you posted. Can you post a minimal reproduction?

I get the same error, if i reference a method 'bar' which is not defined in the 'methods' object of the vue component.

Template

<template>
<div>
<button id="foo" @click="bar">Edit</button>
<input type="text" />
</div>
</template>

If you try to do something like

wrapper.find("input").trigger("input")

it will fail with the error message above.

I got the same error using the render function.
After debugging, I saw that this occur when they are an an undefined event or an nullable event in the component:

export default {
  render (createElement) {
    return createElement('input', {
      on: {
        input: null,
        change: undefined
      }
    })
  }
}

Hope this will help to fix the issue

I stumbled upon this issue as well, or at least something that looks like it. I found this problem with both the wrapper.update and wrapper.trigger.

I made a JSFiddle to demonstrate the issue here: https://jsfiddle.net/vyaceLhu/2/

Hope this helps and that someone can have a look into this. :)

@johman10 The issue with the code you posted is that you aren't passing in any propsData: https://jsfiddle.net/eddyerburgh/d8739dkq/

I'm closing this issue since there isn't a reproduction we can use to fix the bug. If anyone has this problem in the future, please open an issue with the reproduction, it's very much appreciated!

Was this page helpful?
0 / 5 - 0 ratings