diff --git a/docs/guide/advanced/stubs-shallow-mount.md b/docs/guide/advanced/stubs-shallow-mount.md
index a196712c6..311a4189f 100644
--- a/docs/guide/advanced/stubs-shallow-mount.md
+++ b/docs/guide/advanced/stubs-shallow-mount.md
@@ -139,6 +139,45 @@ test('shallow stubs out all child components', () => {
If you used VTU V1, you may remember this as `shallowMount`. That method is still available, too - it's the same as writing `shallow: true`.
:::
+## Stubbing all children components with exceptions
+
+Sometimes you want to stub out _all_ the custom components, _except_ specific one. Let's consider an example:
+
+```js
+const ComplexA = {
+ template: '
Hello from real component!
'
+}
+
+const ComplexComponent = {
+ components: { ComplexA, ComplexB, ComplexC },
+ template: `
+ Welcome to Vue.js 3
+
+
+
+ `
+}
+```
+
+By using `shallow` mounting option that will automatically stub out all the child components. If we want to explicitly opt-out of stubbing specific component, we could provide its name in `stubs` with value set to `false`
+
+```js {3}
+test('shallow allows opt-out of stubbing specific component', () => {
+ const wrapper = mount(ComplexComponent, {
+ shallow: true,
+ stubs: { ComplexA: false }
+ })
+
+ console.log(wrapper.html())
+ /*
+ Welcome to Vue.js 3
+ Hello from real component!
+
+
+ */
+})
+```
+
## Stubbing an async component
In case you want to stub out an async component, then there are two behaviours. For example, you might have components like this:
diff --git a/src/stubs.ts b/src/stubs.ts
index ae49c4979..7fd443d3b 100644
--- a/src/stubs.ts
+++ b/src/stubs.ts
@@ -188,6 +188,11 @@ export function stubComponents(
return [stubs[name], props, children, patchFlag, dynamicProps]
}
+ if (stub === false) {
+ // we explicitly opt out of stubbing this component
+ return args
+ }
+
// we return a stub by matching Vue's `h` function
// where the signature is h(Component, props, slots)
// case 1: default stub
diff --git a/tests/shallowMount.spec.ts b/tests/shallowMount.spec.ts
index 8e5b9b2f9..15c7379f8 100644
--- a/tests/shallowMount.spec.ts
+++ b/tests/shallowMount.spec.ts
@@ -91,6 +91,28 @@ describe('shallowMount', () => {
)
})
+ it('stubs all components, but allows disabling stub by passing false', () => {
+ const wrapper = mount(ComponentWithChildren, {
+ shallow: true,
+ global: {
+ stubs: {
+ Hello: false
+ }
+ }
+ })
+ expect(wrapper.html()).toEqual(
+ '\n' +
+ '
\n' +
+ '
Hello world
\n' +
+ '
\n' +
+ '
\n' +
+ '
\n' +
+ '
\n' +
+ '
\n' +
+ '
'
+ )
+ })
+
it('stubs all components in a script setup component', () => {
const wrapper = mount(ScriptSetupWithChildren, {
shallow: true,