Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: findComponent() without a wrapper no longer works with version >= 2.4.5 #2543

Open
Louis-Stekhoven-Smith opened this issue Nov 14, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@Louis-Stekhoven-Smith
Copy link

Louis-Stekhoven-Smith commented Nov 14, 2024

Describe the bug

using findComponent(Test) without a wrapper no longer works after upgrading version >=2.4.5

To Reproduce

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

function Test(props, context) {
    return h('div', {
        ...props,
        innerHTML: 'This is a test',
    });
}

describe('Mounting component', () => {
    test('with wrapper', () => {
        const Wrapper = {
            components: { Test },
            template: `<Test />`,
        };

        const wrapper = mount(Wrapper, {});
        const item = wrapper.findComponent(Test);
        expect(item.exists()).toBe(true);
    });

    // this test fails now, findComponent returns [Object: null prototype] {} 
    test('without wrapper', () => {
        const wrapper = mount(Test, {});
        const item = wrapper.findComponent(Test);
        expect(item.exists()).toBe(true);
        expect(item.html()).toStrictEqual('<div>This is a test</div>');
    });
});

Finding components by querySelector seems to still work though

        wrapper.findComponent('.foo')
        wrapper.findComponent('[data-test="foo"]')

Expected behavior
Both tests should pass.

@Louis-Stekhoven-Smith Louis-Stekhoven-Smith added the bug Something isn't working label Nov 14, 2024
@cexbrayat
Copy link
Member

hi @Louis-Stekhoven-Smith

Interesting. I'm not sure that's a big deal, as finding the component you just mounted is probably not very common.
But if you really want to see this fix, feel free to open a PR, that would be great!
The code you're looking for is probably the matches function

export function matches(

@cexbrayat
Copy link
Member

(and if you know which version introduced the regression, you can probably pinpoint the culprit commit by adding a unit test that reproduces your issue. You'll then have a good idea how to fix it)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants