Skip to content

Commit

Permalink
fix: use for in to stub components on prototype (#845)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyerburgh authored Jul 22, 2018
1 parent 17dfdc8 commit b6a3659
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
7 changes: 3 additions & 4 deletions packages/shared/stub-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,14 +246,13 @@ export function createComponentStubsForGlobals (
instance: Component
): Components {
const components = {}
Object.keys(instance.options.components).forEach(c => {
for (const c in instance.options.components) {
if (isRequiredComponent(c)) {
return
continue
}

components[c] = createBlankStub(instance.options.components[c], c)
delete instance.options.components[c]._Ctor
delete components[c]._Ctor
})
}
return components
}
19 changes: 18 additions & 1 deletion test/specs/shallow-mount.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { compileToFunctions } from 'vue-template-compiler'
import Vue from 'vue'
import { mount, shallowMount } from '~vue/test-utils'
import { mount, shallowMount, createLocalVue } from '~vue/test-utils'
import Component from '~resources/components/component.vue'
import ComponentWithChild from '~resources/components/component-with-child.vue'
import ComponentWithNestedChildren from '~resources/components/component-with-nested-children.vue'
Expand Down Expand Up @@ -256,6 +256,23 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => {
.to.equal('hey')
})

it('stubs components registered on localVue after multiple installs', () => {
const myPlugin = function (_Vue, opts) {
_Vue.mixin({ })
}
const localVue = createLocalVue()
localVue.component('registered-component', {
render: h => h('time')
})
const TestComponent = {
render: h => h('registered-component')
}

localVue.use(myPlugin)
const wrapper = shallowMount(TestComponent, { localVue })
expect(wrapper.html()).to.contain('registered-component-stub')
})

it('throws an error when the component fails to mount', () => {
expect(() =>
shallowMount({
Expand Down

0 comments on commit b6a3659

Please sign in to comment.