Skip to content

Set name when stubbing components by string #1325

Open
@hackel

Description

@hackel

What problem does this feature solve?

When stubbing a child component like:

wrapper = shallowMount(ComponentUnderTest, {
    stubs: ['StringComponent'],
});

It is not possible to find the stubbed component using wrapper.find({ name: 'StringComponent' }) because it does not have a name.

In my case, I am stubbing an input component, and want to simulate it emitting an event in order to test the response in the parent component.

What does the proposed API look like?

It looks like this could be a simple change in https://github.com/vuejs/vue-test-utils/blob/dev/packages/create-instance/create-component-stubs.js#L90

    if (!componentOptions.name) {
        componentOptions.name = name;
    }

In my own testing this has been working fine, but I'm not familiar enough with the code yet to know if there might be any side-effects from this so I wanted to raise the issue before creating a PR.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions