Vue-test-utils: .contains() not working when <Component> is passed

Created on 19 Dec 2017  路  2Comments  路  Source: vuejs/vue-test-utils

Hey guys,

I have the next test-case:

import ParentComponent from './ParentComponent'
import ChildComponent from './ChildComponent'

it('does not render <ChildComponent>', () => {
    const wrapper = shallow(ParentComponent)
    expect(wrapper.contains(ChildComponent)).toBe(false)
  })

ParentComponent:

<template>
  <div>
    <AnotherComponent />
    <ChildComponent />
  </div>
</template>
<script></script>

However the test fails.

After debugging I found out selector.name is undefined:
https://github.com/vuejs/vue-test-utils/blob/dev/src/wrappers/wrapper.js#L78

unless I explicitly declare ChildComponent as this (which makes my test to pass):

<template>...</template>
<script>
  export default {
    name: 'ChildComponent'
  }
</script>

otherwise selector.name is always undefined.

Printscreen

screen shot 2017-12-19 at 4 35 25 pm

Any thought will be well appreciated,
Cheers.

Note: shallow and mount behave the same

Most helpful comment

It's worth noting that contains has been updated to include the wrapper element. So in beta.9 it will behave as you originally expected 馃榾

All 2 comments

nvm I just confirmed that's expected
https://vue-test-utils.vuejs.org/en/api/selectors.html
thanks anyway

It's worth noting that contains has been updated to include the wrapper element. So in beta.9 it will behave as you originally expected 馃榾

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dwonisch picture dwonisch  路  3Comments

kjugi picture kjugi  路  3Comments

matt-sanders picture matt-sanders  路  3Comments

benm-eras picture benm-eras  路  3Comments

38elements picture 38elements  路  3Comments