Bug: stubs
does not respect globally registered component names
#2541
Labels
bug
Something isn't working
stubs
does not respect globally registered component names
#2541
Describe the bug
When stubbing child components using the
stubs
option, vue-test-utils will not match components against the name they have been registered under, but by the internal name given to them by the Vue compiler.e.g. If the
Example.vue
component is added to a Vue app usingapp.component('VtuExample', Example)
,stubs : { VtuExample: true }
will not mock the component, butstubs : { example: true }
will.To Reproduce
/lib
folder and execute the commandnpm i && npm run build
/app
folder and execute the commandnpm i && npm test
Expected behavior
Both tests in
App.spec.ts
should pass, as the component imported from /lib has been registered and used under the name "HelloWorld", not "hello".Related information:
Additional context
With the increasing prevalence of the Composition API, it is no longer common to manually define a name for each written component (as can be done when using Options API). When you globally register a component using
app.component('name', component)
, for all intents and purposes within your code the component is calledname
. It's not possible anywhere in your code to use it's internal name to include it in templates. So from a test authors perspective, it is not obvious that the component can't be stubbed using the registered name, but only the Vue compiler generated name.The text was updated successfully, but these errors were encountered: