From f114381ab6cf6db5188aa826227416e7f8b54834 Mon Sep 17 00:00:00 2001 From: freakzlike Date: Fri, 8 Apr 2022 15:56:04 +0200 Subject: [PATCH 1/2] fix: disable stubs for built-in components on shallow --- src/stubs.ts | 21 ++- tests/mountingOptions/global.stubs.spec.ts | 188 ++++++++++++++------- 2 files changed, 138 insertions(+), 71 deletions(-) diff --git a/src/stubs.ts b/src/stubs.ts index 5e94654b2..397072e2e 100644 --- a/src/stubs.ts +++ b/src/stubs.ts @@ -13,7 +13,7 @@ import { import { hyphenate } from './utils/vueShared' import { matchName } from './utils/matchName' import { isComponent, isFunctionalComponent } from './utils' -import { ComponentInternalInstance } from '@vue/runtime-core' +import { ComponentInternalInstance, BaseTransition } from '@vue/runtime-core' import { unwrapLegacyVueExtendComponent } from './utils/vueCompatSupport' import { Stub, Stubs } from './types' import { @@ -157,7 +157,12 @@ export function stubComponents( const type = nodeType as VNodeTypes | typeof Teleport // stub transition by default via config.global.stubs - if (type === Transition && 'transition' in stubs && stubs['transition']) { + if ( + (type === Transition || type === BaseTransition) && + 'transition' in stubs + ) { + if (stubs.transition === false) return args + return [ createStub({ name: 'transition', @@ -169,11 +174,9 @@ export function stubComponents( } // stub transition-group by default via config.global.stubs - if ( - type === TransitionGroup && - 'transition-group' in stubs && - stubs['transition-group'] - ) { + if (type === TransitionGroup && 'transition-group' in stubs) { + if (stubs['transition-group'] === false) return args + return [ createStub({ name: 'transition-group', @@ -185,7 +188,9 @@ export function stubComponents( } // stub teleport by default via config.global.stubs - if (type === Teleport && 'teleport' in stubs && stubs['teleport']) { + if (type === Teleport && 'teleport' in stubs) { + if (stubs.teleport === false) return args + return [ createStub({ name: 'teleport', diff --git a/tests/mountingOptions/global.stubs.spec.ts b/tests/mountingOptions/global.stubs.spec.ts index c23d4ecfc..0f44ac36c 100644 --- a/tests/mountingOptions/global.stubs.spec.ts +++ b/tests/mountingOptions/global.stubs.spec.ts @@ -392,87 +392,149 @@ describe('mounting options: stubs', () => { ) }) - it('stubs transition by default', () => { - const Comp = { - template: `
` - } - const wrapper = mount(Comp) + describe('transition', () => { + it('stubs transition by default', () => { + const Comp = { + template: `
` + } + const wrapper = mount(Comp) - expect(wrapper.html()).toBe( - '\n' + - '
\n' + - '
' - ) - }) + expect(wrapper.html()).toBe( + '\n' + + '
\n' + + '
' + ) + }) - it('opts out of stubbing transition by default', () => { - const Comp = { - template: `
` - } - const wrapper = mount(Comp, { - global: { - stubs: { - transition: false - } + it('opts out of stubbing transition by default', () => { + const Comp = { + template: `
` } + const wrapper = mount(Comp, { + global: { + stubs: { + transition: false + } + } + }) + + // Vue removes at run-time and does it's magic, so should not + // appear in the html when it isn't stubbed. + expect(wrapper.html()).toBe('
') }) - // Vue removes at run-time and does it's magic, so should not - // appear in the html when it isn't stubbed. - expect(wrapper.html()).toBe('
') + it('does not stub transition on shallow with false', () => { + const Comp = { + template: `
` + } + const wrapper = mount(Comp, { + shallow: true, + global: { + stubs: { + transition: false + } + } + }) + + // Vue removes at run-time and does it's magic, so should not + // appear in the html when it isn't stubbed. + expect(wrapper.html()).toBe('
') + }) }) - it('opts out of stubbing transition-group by default', () => { - const Comp = { - template: `
` - } - const wrapper = mount(Comp, { - global: { - stubs: { - 'transition-group': false - } + describe('transition-group', () => { + it('stubs transition-group by default', () => { + const Comp = { + template: `
` } + const wrapper = mount(Comp) + expect(wrapper.find('#content').exists()).toBe(true) }) - // Vue removes at run-time and does it's magic, so should not - // appear in the html when it isn't stubbed. - expect(wrapper.html()).toBe('
') - }) + it('opts out of stubbing transition-group by default', () => { + const Comp = { + template: `
` + } + const wrapper = mount(Comp, { + global: { + stubs: { + 'transition-group': false + } + } + }) - it('stubs transition-group by default', () => { - const Comp = { - template: `
` - } - const wrapper = mount(Comp) - expect(wrapper.find('#content').exists()).toBe(true) - }) + // Vue removes at run-time and does it's magic, so should not + // appear in the html when it isn't stubbed. + expect(wrapper.html()).toBe('
') + }) - it('does not stub teleport by default', () => { - const Comp = { - template: `
` - } - const wrapper = mount(Comp) + it('does not stub transition-group on shallow with false', () => { + const Comp = { + template: `
` + } + const wrapper = mount(Comp, { + shallow: true, + global: { + stubs: { + 'transition-group': false + } + } + }) - expect(wrapper.html()).toBe( - '\n' + '' - ) + // Vue removes at run-time and does it's magic, so should not + // appear in the html when it isn't stubbed. + expect(wrapper.html()).toBe('
') + }) }) - it('opts in to stubbing teleport ', () => { - const Comp = { - template: `
` - } - const wrapper = mount(Comp, { - global: { - stubs: { - teleport: true - } + describe('teleport', () => { + it('does not stub teleport by default', () => { + const Comp = { + template: `
` } + const wrapper = mount(Comp) + + expect(wrapper.html()).toBe( + '\n' + '' + ) }) - expect(wrapper.html()).toBe( - '\n' + '
\n' + '
' - ) + it('opts in to stubbing teleport ', () => { + const Comp = { + template: `
` + } + const wrapper = mount(Comp, { + global: { + stubs: { + teleport: true + } + } + }) + + expect(wrapper.html()).toBe( + '\n' + + '
\n' + + '
' + ) + }) + + it('does not stub teleport with shallow', () => { + const Comp = { + template: `
` + } + const wrapper = mount(Comp, { + shallow: true, + global: { + stubs: { + teleport: false + } + } + }) + + expect(wrapper.html()).toBe( + '\n' + '' + ) + }) }) it('stubs component by key prior before name', () => { From 6a373606f773a281b57133eab102fdcc51bdfd74 Mon Sep 17 00:00:00 2001 From: freakzlike Date: Fri, 8 Apr 2022 16:15:25 +0200 Subject: [PATCH 2/2] fix: wrong import of BaseTransition --- src/stubs.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/stubs.ts b/src/stubs.ts index 397072e2e..cf3977815 100644 --- a/src/stubs.ts +++ b/src/stubs.ts @@ -2,6 +2,7 @@ import { transformVNodeArgs, Transition, TransitionGroup, + BaseTransition, Teleport, h, defineComponent, @@ -13,7 +14,7 @@ import { import { hyphenate } from './utils/vueShared' import { matchName } from './utils/matchName' import { isComponent, isFunctionalComponent } from './utils' -import { ComponentInternalInstance, BaseTransition } from '@vue/runtime-core' +import { ComponentInternalInstance } from '@vue/runtime-core' import { unwrapLegacyVueExtendComponent } from './utils/vueCompatSupport' import { Stub, Stubs } from './types' import {