Skip to content

Test child component, which is the root element #2070

Open
@souphuhn

Description

@souphuhn

Subject of the issue

Example:
Lets say I have the following parent component:

// ParentComponent
<template>
   <child-component :prop-a="propA" :prop-b="propB" />
</template>

When unit testing my ParentComponent I want to check the correct usage of the underlying ChildComponent as well and test its properties. Back in Vue2 I normally did:

const wrapper = shallowMount(ParentComponent);
const child = wrapper.vm.$children[0];

expect(child.$props.....).toBe(...);
expect(child.$props.....).toBe(....);
expect(child.$props.....).toBe(....);

I used the wrapper.vm.$children[0] approach, because wrapper.find(ChildComponent) would return the same wrapper again. (because it is the root)

Now my question is: How can I select the child-component in Vue3 to tests its properties?

Steps to reproduce

Tell us how to reproduce this issue. Please provide a working and simplified example.

Expected behaviour

What should happen?

Actual behaviour

What happens instead?

Possible Solution

What are the alternative solutions? Please describe what else you have considered?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions