Skip to content

Commit 5e34d41

Browse files
authored
fix: allow to use Teleport, Transition and TransitionGroup in PascalCase in stubs (#2073)
Fixes #2072
1 parent b2b3158 commit 5e34d41

File tree

2 files changed

+93
-6
lines changed

2 files changed

+93
-6
lines changed

src/vnodeTransformers/stubComponentsTransformer.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,9 @@ export function createStubComponentsTransformer({
135135
}: CreateStubComponentsTransformerConfig): VTUVNodeTypeTransformer {
136136
return function componentsTransformer(type, instance) {
137137
// stub teleport by default via config.global.stubs
138-
if (isTeleport(type) && 'teleport' in stubs) {
139-
if (stubs.teleport === false) return type
138+
if (isTeleport(type) && ('teleport' in stubs || 'Teleport' in stubs)) {
139+
if ('teleport' in stubs && stubs['teleport'] === false) return type
140+
if ('Teleport' in stubs && stubs['Teleport'] === false) return type
140141

141142
return createStub({
142143
name: 'teleport',
@@ -160,9 +161,10 @@ export function createStubComponentsTransformer({
160161
// stub transition by default via config.global.stubs
161162
if (
162163
(type === Transition || (type as any) === BaseTransition) &&
163-
'transition' in stubs
164+
('transition' in stubs || 'Transition' in stubs)
164165
) {
165-
if (stubs.transition === false) return type
166+
if ('transition' in stubs && stubs['transition'] === false) return type
167+
if ('Transition' in stubs && stubs['Transition'] === false) return type
166168

167169
return createStub({
168170
name: 'transition',
@@ -172,8 +174,14 @@ export function createStubComponentsTransformer({
172174
}
173175

174176
// stub transition-group by default via config.global.stubs
175-
if ((type as any) === TransitionGroup && 'transition-group' in stubs) {
176-
if (stubs['transition-group'] === false) return type
177+
if (
178+
(type as any) === TransitionGroup &&
179+
('transition-group' in stubs || 'TransitionGroup' in stubs)
180+
) {
181+
if ('transition-group' in stubs && stubs['transition-group'] === false)
182+
return type
183+
if ('TransitionGroup' in stubs && stubs['TransitionGroup'] === false)
184+
return type
177185

178186
return createStub({
179187
name: 'transition-group',

tests/mountingOptions/global.stubs.spec.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,36 @@ describe('mounting options: stubs', () => {
452452
// appear in the html when it isn't stubbed.
453453
expect(wrapper.html()).toBe('<div id="content"></div>')
454454
})
455+
456+
it('does not stub transition after overriding config.global.stubs', () => {
457+
const Comp = {
458+
template: `<transition><div id="content-global-stubs-no-transition" /></transition>`
459+
}
460+
config.global.stubs = {}
461+
const wrapper = mount(Comp)
462+
463+
// Vue removes <transition> at run-time and does it's magic, so <transition> should not
464+
// appear in the html when it isn't stubbed.
465+
expect(wrapper.html()).toBe(
466+
'<div id="content-global-stubs-no-transition"></div>'
467+
)
468+
})
469+
470+
it('stub transition after overriding config.global.stubs with Transition: true PascalCase', () => {
471+
const Comp = {
472+
template: `<transition><div id="content-global-stubs-transition" /></transition>`
473+
}
474+
config.global.stubs = {
475+
Transition: true
476+
}
477+
const wrapper = mount(Comp)
478+
479+
expect(wrapper.html()).toBe(
480+
'<transition-stub appear="false" persisted="false" css="true">\n' +
481+
' <div id="content-global-stubs-transition"></div>\n' +
482+
'</transition-stub>'
483+
)
484+
})
455485
})
456486

457487
describe('transition-group', () => {
@@ -497,6 +527,36 @@ describe('mounting options: stubs', () => {
497527
// appear in the html when it isn't stubbed.
498528
expect(wrapper.html()).toBe('<div id="content"></div>')
499529
})
530+
531+
it('does not stub transition-group after overriding config.global.stubs', () => {
532+
const Comp = {
533+
template: `<transition-group><div key="content" id="content-global-stubs-no-transition-group" /></transition-group>`
534+
}
535+
config.global.stubs = {}
536+
const wrapper = mount(Comp)
537+
538+
// Vue removes <transition-group> at run-time and does it's magic, so <transition-group> should not
539+
// appear in the html when it isn't stubbed.
540+
expect(wrapper.html()).toBe(
541+
'<div id="content-global-stubs-no-transition-group"></div>'
542+
)
543+
})
544+
545+
it('stub transition-group after overriding config.global.stubs with TransitionGroup: true in PascalCase', () => {
546+
const Comp = {
547+
template: `<transition-group><div key="content" id="content-global-stubs-transition-group" /></transition-group>`
548+
}
549+
config.global.stubs = {
550+
TransitionGroup: true
551+
}
552+
const wrapper = mount(Comp)
553+
554+
expect(wrapper.html()).toBe(
555+
'<transition-group-stub appear="false" persisted="false" css="true">\n' +
556+
' <div id="content-global-stubs-transition-group"></div>\n' +
557+
'</transition-group-stub>'
558+
)
559+
})
500560
})
501561

502562
describe('teleport', () => {
@@ -551,6 +611,25 @@ describe('mounting options: stubs', () => {
551611
'<!--teleport start-->\n' + '<!--teleport end-->'
552612
)
553613
})
614+
615+
it('opts in to stubbing teleport with Teleport: true', () => {
616+
const Comp = {
617+
template: `<teleport to="body"><div id="content-global-stubs-teleport" /></teleport>`
618+
}
619+
const wrapper = mount(Comp, {
620+
global: {
621+
stubs: {
622+
Teleport: true
623+
}
624+
}
625+
})
626+
627+
expect(wrapper.html()).toBe(
628+
'<teleport-stub to="body">\n' +
629+
' <div id="content-global-stubs-teleport"></div>\n' +
630+
'</teleport-stub>'
631+
)
632+
})
554633
})
555634

556635
describe('keep-alive', () => {

0 commit comments

Comments
 (0)