Skip to content

Commit eb82845

Browse files
authored
fix: disable stubs for built-in components on shallow (#1409)
* fix: disable stubs for built-in components on shallow * fix: wrong import of BaseTransition
1 parent 3ce2443 commit eb82845

File tree

2 files changed

+138
-70
lines changed

2 files changed

+138
-70
lines changed

src/stubs.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
transformVNodeArgs,
33
Transition,
44
TransitionGroup,
5+
BaseTransition,
56
Teleport,
67
h,
78
defineComponent,
@@ -157,7 +158,12 @@ export function stubComponents(
157158
const type = nodeType as VNodeTypes | typeof Teleport
158159

159160
// stub transition by default via config.global.stubs
160-
if (type === Transition && 'transition' in stubs && stubs['transition']) {
161+
if (
162+
(type === Transition || type === BaseTransition) &&
163+
'transition' in stubs
164+
) {
165+
if (stubs.transition === false) return args
166+
161167
return [
162168
createStub({
163169
name: 'transition',
@@ -169,11 +175,9 @@ export function stubComponents(
169175
}
170176

171177
// stub transition-group by default via config.global.stubs
172-
if (
173-
type === TransitionGroup &&
174-
'transition-group' in stubs &&
175-
stubs['transition-group']
176-
) {
178+
if (type === TransitionGroup && 'transition-group' in stubs) {
179+
if (stubs['transition-group'] === false) return args
180+
177181
return [
178182
createStub({
179183
name: 'transition-group',
@@ -185,7 +189,9 @@ export function stubComponents(
185189
}
186190

187191
// stub teleport by default via config.global.stubs
188-
if (type === Teleport && 'teleport' in stubs && stubs['teleport']) {
192+
if (type === Teleport && 'teleport' in stubs) {
193+
if (stubs.teleport === false) return args
194+
189195
return [
190196
createStub({
191197
name: 'teleport',

tests/mountingOptions/global.stubs.spec.ts

Lines changed: 125 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -392,87 +392,149 @@ describe('mounting options: stubs', () => {
392392
)
393393
})
394394

395-
it('stubs transition by default', () => {
396-
const Comp = {
397-
template: `<transition><div id="content" /></transition>`
398-
}
399-
const wrapper = mount(Comp)
395+
describe('transition', () => {
396+
it('stubs transition by default', () => {
397+
const Comp = {
398+
template: `<transition><div id="content" /></transition>`
399+
}
400+
const wrapper = mount(Comp)
400401

401-
expect(wrapper.html()).toBe(
402-
'<transition-stub>\n' +
403-
' <div id="content"></div>\n' +
404-
'</transition-stub>'
405-
)
406-
})
402+
expect(wrapper.html()).toBe(
403+
'<transition-stub>\n' +
404+
' <div id="content"></div>\n' +
405+
'</transition-stub>'
406+
)
407+
})
407408

408-
it('opts out of stubbing transition by default', () => {
409-
const Comp = {
410-
template: `<transition><div id="content" /></transition>`
411-
}
412-
const wrapper = mount(Comp, {
413-
global: {
414-
stubs: {
415-
transition: false
416-
}
409+
it('opts out of stubbing transition by default', () => {
410+
const Comp = {
411+
template: `<transition><div id="content" /></transition>`
417412
}
413+
const wrapper = mount(Comp, {
414+
global: {
415+
stubs: {
416+
transition: false
417+
}
418+
}
419+
})
420+
421+
// Vue removes <transition> at run-time and does it's magic, so <transition> should not
422+
// appear in the html when it isn't stubbed.
423+
expect(wrapper.html()).toBe('<div id="content"></div>')
418424
})
419425

420-
// Vue removes <transition> at run-time and does it's magic, so <transition> should not
421-
// appear in the html when it isn't stubbed.
422-
expect(wrapper.html()).toBe('<div id="content"></div>')
426+
it('does not stub transition on shallow with false', () => {
427+
const Comp = {
428+
template: `<transition><div id="content" /></transition>`
429+
}
430+
const wrapper = mount(Comp, {
431+
shallow: true,
432+
global: {
433+
stubs: {
434+
transition: false
435+
}
436+
}
437+
})
438+
439+
// Vue removes <transition> at run-time and does it's magic, so <transition> should not
440+
// appear in the html when it isn't stubbed.
441+
expect(wrapper.html()).toBe('<div id="content"></div>')
442+
})
423443
})
424444

425-
it('opts out of stubbing transition-group by default', () => {
426-
const Comp = {
427-
template: `<transition-group><div key="content" id="content" /></transition-group>`
428-
}
429-
const wrapper = mount(Comp, {
430-
global: {
431-
stubs: {
432-
'transition-group': false
433-
}
445+
describe('transition-group', () => {
446+
it('stubs transition-group by default', () => {
447+
const Comp = {
448+
template: `<transition-group><div key="a" id="content" /></transition-group>`
434449
}
450+
const wrapper = mount(Comp)
451+
expect(wrapper.find('#content').exists()).toBe(true)
435452
})
436453

437-
// Vue removes <transition-group> at run-time and does it's magic, so <transition-group> should not
438-
// appear in the html when it isn't stubbed.
439-
expect(wrapper.html()).toBe('<div id="content"></div>')
440-
})
454+
it('opts out of stubbing transition-group by default', () => {
455+
const Comp = {
456+
template: `<transition-group><div key="content" id="content" /></transition-group>`
457+
}
458+
const wrapper = mount(Comp, {
459+
global: {
460+
stubs: {
461+
'transition-group': false
462+
}
463+
}
464+
})
441465

442-
it('stubs transition-group by default', () => {
443-
const Comp = {
444-
template: `<transition-group><div key="a" id="content" /></transition-group>`
445-
}
446-
const wrapper = mount(Comp)
447-
expect(wrapper.find('#content').exists()).toBe(true)
448-
})
466+
// Vue removes <transition-group> at run-time and does it's magic, so <transition-group> should not
467+
// appear in the html when it isn't stubbed.
468+
expect(wrapper.html()).toBe('<div id="content"></div>')
469+
})
449470

450-
it('does not stub teleport by default', () => {
451-
const Comp = {
452-
template: `<teleport to="body"><div id="content" /></teleport>`
453-
}
454-
const wrapper = mount(Comp)
471+
it('does not stub transition-group on shallow with false', () => {
472+
const Comp = {
473+
template: `<transition-group><div key="content" id="content" /></transition-group>`
474+
}
475+
const wrapper = mount(Comp, {
476+
shallow: true,
477+
global: {
478+
stubs: {
479+
'transition-group': false
480+
}
481+
}
482+
})
455483

456-
expect(wrapper.html()).toBe(
457-
'<!--teleport start-->\n' + '<!--teleport end-->'
458-
)
484+
// Vue removes <transition-group> at run-time and does it's magic, so <transition-group> should not
485+
// appear in the html when it isn't stubbed.
486+
expect(wrapper.html()).toBe('<div id="content"></div>')
487+
})
459488
})
460489

461-
it('opts in to stubbing teleport ', () => {
462-
const Comp = {
463-
template: `<teleport to="body"><div id="content" /></teleport>`
464-
}
465-
const wrapper = mount(Comp, {
466-
global: {
467-
stubs: {
468-
teleport: true
469-
}
490+
describe('teleport', () => {
491+
it('does not stub teleport by default', () => {
492+
const Comp = {
493+
template: `<teleport to="body"><div id="content" /></teleport>`
470494
}
495+
const wrapper = mount(Comp)
496+
497+
expect(wrapper.html()).toBe(
498+
'<!--teleport start-->\n' + '<!--teleport end-->'
499+
)
471500
})
472501

473-
expect(wrapper.html()).toBe(
474-
'<teleport-stub>\n' + ' <div id="content"></div>\n' + '</teleport-stub>'
475-
)
502+
it('opts in to stubbing teleport ', () => {
503+
const Comp = {
504+
template: `<teleport to="body"><div id="content" /></teleport>`
505+
}
506+
const wrapper = mount(Comp, {
507+
global: {
508+
stubs: {
509+
teleport: true
510+
}
511+
}
512+
})
513+
514+
expect(wrapper.html()).toBe(
515+
'<teleport-stub>\n' +
516+
' <div id="content"></div>\n' +
517+
'</teleport-stub>'
518+
)
519+
})
520+
521+
it('does not stub teleport with shallow', () => {
522+
const Comp = {
523+
template: `<teleport to="body"><div id="content" /></teleport>`
524+
}
525+
const wrapper = mount(Comp, {
526+
shallow: true,
527+
global: {
528+
stubs: {
529+
teleport: false
530+
}
531+
}
532+
})
533+
534+
expect(wrapper.html()).toBe(
535+
'<!--teleport start-->\n' + '<!--teleport end-->'
536+
)
537+
})
476538
})
477539

478540
it('stubs component by key prior before name', () => {

0 commit comments

Comments
 (0)