diff --git a/src/mount.ts b/src/mount.ts
index c0ad9d4bf..baf42a76c 100644
--- a/src/mount.ts
+++ b/src/mount.ts
@@ -420,6 +420,10 @@ export function mount(
// ref: https://github.com/vuejs/vue-test-utils-next/issues/425
if (global?.stubs) {
for (const [name, stub] of Object.entries(global.stubs)) {
+ // removes a previously component with the same name if it exists
+ // and avoids the warning from vue-next
+ // "Component has already been registered in target app."
+ delete app._context.components[name]
if (stub === true) {
const stubbed = createStub({ name, props: {} })
// default stub.
diff --git a/tests/mountingOptions/stubs.global.spec.ts b/tests/mountingOptions/stubs.global.spec.ts
index 0597f05ab..9a7d548ce 100644
--- a/tests/mountingOptions/stubs.global.spec.ts
+++ b/tests/mountingOptions/stubs.global.spec.ts
@@ -4,6 +4,7 @@ import { config, mount, RouterLinkStub } from '../../src'
import Hello from '../components/Hello.vue'
import ComponentWithoutName from '../components/ComponentWithoutName.vue'
import ComponentWithSlots from '../components/ComponentWithSlots.vue'
+import { createRouter, createWebHistory } from 'vue-router'
describe('mounting options: stubs', () => {
let configStubsSave = config.global.stubs
@@ -83,6 +84,34 @@ describe('mounting options: stubs', () => {
)
})
+ it('does not warn if stubbing an already registered component', () => {
+ // a component with RouterView
+ const Comp = defineComponent({
+ template: '