Skip to content

findComponent problem ? #173

@bastarder

Description

@bastarder

Subject of the issue

findComponent don't return expected wrappers

Steps to reproduce

import { mount } from '@vue/test-utils'

describe('A.vue', () => {
  test('create', async () => {
    const ComponentA = {
      name: 'ComponentA',
      template: `
        <div>
          <slot></slot>
        </div>
      `,
    }

    const ComponentB = {
      name: 'ComponentB',
      template: `
        <div>
          <slot></slot>
        </div>
      `,
    }
    const wrapper = mount({
      components: {
        ComponentA,
        ComponentB,
      },
      template: `
        <ComponentA>
          <ComponentB>1</ComponentB>
          <ComponentB>2</ComponentB>
          <ComponentB>3</ComponentB>
        </ComponentA>
      `,
    })
    const com1 = wrapper.findComponent(ComponentB)
    console.log(com1.html())  // why this wrapper html is `<div>1</div><div>2</div><div>3</div>` ?
    const com2 = wrapper.findAllComponents(ComponentB)
    console.log(com2[0].html())  // `<div>1</div><div>2</div><div>3</div>`
    console.log(com2[1].html())  // `<div>1</div><div>2</div><div>3</div>`
    console.log(com2[2].html())  // `<div>1</div><div>2</div><div>3</div>`
  })
})

Expected behaviour

com1.html()  =>>>> '<div>1</div>'
com2[2].html() =>>>> '<div>3</div>'

Actual behaviour

com1.html()  =>>>> '<div>1</div><div>2</div><div>3</div>'
com2[2].html() =>>>> '<div>1</div><div>2</div><div>3</div>'

Possible Solution

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions