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

38elements picture 38elements  路  3Comments

AustinGil picture AustinGil  路  3Comments

vwxyutarooo picture vwxyutarooo  路  3Comments

yoyoys picture yoyoys  路  3Comments

maerteijn picture maerteijn  路  3Comments