Vue-test-utils: Set name when stubbing components by string

Created on 21 Oct 2019  路  1Comment  路  Source: vuejs/vue-test-utils

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.

Most helpful comment

@eddyerburgh i think this makes much sense. I dont see a reason not to do it?

>All comments

@eddyerburgh i think this makes much sense. I dont see a reason not to do it?

Was this page helpful?
0 / 5 - 0 ratings