From 3aaae60c8b862dd5f20a5bee4b2845108d9f8b5c Mon Sep 17 00:00:00 2001 From: Illya Klymov Date: Wed, 30 Jun 2021 08:44:43 +0300 Subject: [PATCH] fix(shallow): correctly stub anonymous components (#714) --- src/stubs.ts | 5 ----- tests/mountingOptions/global.stubs.spec.ts | 24 ++++++++++++++++++++++ tests/shallowMount.spec.ts | 4 ++-- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/stubs.ts b/src/stubs.ts index f0ec2d35e..72b3adea9 100644 --- a/src/stubs.ts +++ b/src/stubs.ts @@ -173,11 +173,6 @@ export function stubComponents( const registeredName = getComponentRegisteredName(instance, type) const componentName = type['name'] || type['displayName'] - // No name found? - if (!registeredName && !componentName) { - return renderStubDefaultSlot || !shallow ? args : ['stub'] - } - let stub = null let name = null diff --git a/tests/mountingOptions/global.stubs.spec.ts b/tests/mountingOptions/global.stubs.spec.ts index 501c8dea2..124279850 100644 --- a/tests/mountingOptions/global.stubs.spec.ts +++ b/tests/mountingOptions/global.stubs.spec.ts @@ -670,4 +670,28 @@ describe('mounting options: stubs', () => { ) }) }) + + it('renders stub for anonymous component when using shallow mount', () => { + const AnonymousComponent = defineComponent({ + template: `
` + }) + + const WrapperComponent = defineComponent({ + computed: { + cmp() { + return AnonymousComponent + } + }, + template: `test` + }) + + const wrapper = mount(WrapperComponent, { + shallow: true, + global: { + renderStubDefaultSlot: true + } + }) + + expect(wrapper.html()).toBe('test') + }) }) diff --git a/tests/shallowMount.spec.ts b/tests/shallowMount.spec.ts index e950c110c..4779df2da 100644 --- a/tests/shallowMount.spec.ts +++ b/tests/shallowMount.spec.ts @@ -160,8 +160,8 @@ describe('shallowMount', () => { expect(wrapper.html()).toEqual( '
Override
\n' + '\n' + - '\n' + - '\n' + + '\n' + + '\n' + '' ) })