test-utils icon indicating copy to clipboard operation
test-utils copied to clipboard

Bug: findComponent doesn't find anything when using @vue/compat

Open tom751 opened this issue 2 years ago • 4 comments

Describe the bug I'm currently migrating a large Vue 2.7 app over to Vue 3 using the @vue/compat build. The apps work but the tests always fail because findComponent or findAllComponents never seem to find anything when passing in a component. For example, we have a lot of this type of expectation in our tests

expect(wrapper.findComponent(NoticeBanner).exists()).toBe(true)

If I log out the html of the wrapper with wrapper.html(), we can see that the component is there:

<main>
  <noticebanner msg="Hello world"></noticebanner>
</main>

If I add a class to the component, and query that with .find('.some-class'), then that works - but due to the number of component tests I have, it's not really feasible for me to update hundreds of files.

The problem definitely seems to be with using the compat build, because if I remove the alias from the Vite config (vue: '@vue/compat') then findComponent works again.

To Reproduce Here's an example repo showing the issue https://github.com/tom751/vtu-compat-issue - this was a new project created with npm create vue@legacy and then I followed the migration guide to update to Vue 3 with the compat build (see the commits).

  • run npm run test:unit - HomeView.spec.ts will fail
  • comment out vue: '@vue/compat' in vite.config.ts and rerun the tests - they now pass

Expected behavior findComponent/findAllComponents should find the component when it exists and passing it as an argument

Additional context Removing the alias to @vue/compat causes findComponent to work again, but then tests start to fail on Vue 2 syntax that hasn't been migrated yet in the codebase.

I've also tried various versions of vue/test-utils/compat and the behaviour is the same.

tom751 avatar Mar 25 '24 15:03 tom751