Skip to content

Commit b6a3659

Browse files
authored
fix: use for in to stub components on prototype (#845)
1 parent 17dfdc8 commit b6a3659

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

Diff for: packages/shared/stub-components.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,13 @@ export function createComponentStubsForGlobals (
246246
instance: Component
247247
): Components {
248248
const components = {}
249-
Object.keys(instance.options.components).forEach(c => {
249+
for (const c in instance.options.components) {
250250
if (isRequiredComponent(c)) {
251-
return
251+
continue
252252
}
253-
254253
components[c] = createBlankStub(instance.options.components[c], c)
255254
delete instance.options.components[c]._Ctor
256255
delete components[c]._Ctor
257-
})
256+
}
258257
return components
259258
}

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

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { compileToFunctions } from 'vue-template-compiler'
22
import Vue from 'vue'
3-
import { mount, shallowMount } from '~vue/test-utils'
3+
import { mount, shallowMount, createLocalVue } from '~vue/test-utils'
44
import Component from '~resources/components/component.vue'
55
import ComponentWithChild from '~resources/components/component-with-child.vue'
66
import ComponentWithNestedChildren from '~resources/components/component-with-nested-children.vue'
@@ -256,6 +256,23 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
256256
.to.equal('hey')
257257
})
258258

259+
it('stubs components registered on localVue after multiple installs', () => {
260+
const myPlugin = function (_Vue, opts) {
261+
_Vue.mixin({ })
262+
}
263+
const localVue = createLocalVue()
264+
localVue.component('registered-component', {
265+
render: h => h('time')
266+
})
267+
const TestComponent = {
268+
render: h => h('registered-component')
269+
}
270+
271+
localVue.use(myPlugin)
272+
const wrapper = shallowMount(TestComponent, { localVue })
273+
expect(wrapper.html()).to.contain('registered-component-stub')
274+
})
275+
259276
it('throws an error when the component fails to mount', () => {
260277
expect(() =>
261278
shallowMount({

0 commit comments

Comments
 (0)