Skip to content

Commit 5e92c10

Browse files
authored
fix: keep components when adding stubs (#1075)
1 parent d4c118b commit 5e92c10

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

Diff for: packages/create-instance/patch-render.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,9 @@ export function patchRender (_Vue, stubs, stubAllComponents) {
108108
const stub = createStubIfNeeded(stubAllComponents, original, _Vue, el)
109109

110110
if (stub) {
111-
vm.$options.components = {
112-
...vm.$options.components,
111+
Object.assign(vm.$options.components, {
113112
[el]: stub
114-
}
113+
})
115114
modifiedComponents.add(el)
116115
}
117116
}

Diff for: test/specs/shallow-mount.spec.js

+28-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import { describeRunIf, itDoNotRunIf } from 'conditional-specs'
1313

1414
describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
1515
beforeEach(() => {
16-
sinon.stub(console, 'info')
17-
sinon.stub(console, 'error')
16+
sinon.stub(console, 'info').callThrough()
17+
sinon.stub(console, 'error').callThrough()
1818
})
1919

2020
afterEach(() => {
@@ -490,4 +490,30 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
490490
'</div>'
491491
)
492492
})
493+
494+
itDoNotRunIf(
495+
vueVersion < 2.1,
496+
'does not error when rendering a previously stubbed component', () => {
497+
const ChildComponent = {
498+
render: h => h('div')
499+
}
500+
const TestComponent = {
501+
template: `
502+
<div>
503+
<extended-component />
504+
<keep-alive>
505+
<child-component />
506+
</keep-alive>
507+
</div>
508+
`,
509+
components: {
510+
ExtendedComponent: Vue.extend({ render: h => h('div') }),
511+
ChildComponent
512+
}
513+
}
514+
shallowMount(TestComponent)
515+
mount(TestComponent)
516+
expect(console.error)
517+
.not.calledWith(sinon.match('Unknown custom element'))
518+
})
493519
})

0 commit comments

Comments
 (0)