Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/find-vue-components.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
throwError
} from './util'

function findAllVueComponentsFromVm (
export function findAllVueComponentsFromVm (
vm: Component,
components: Array<Component> = []
): Array<Component> {
Expand Down
7 changes: 5 additions & 2 deletions src/mount.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import createElement from './lib/create-element'
import './lib/polyfills/matches-polyfill'
import './lib/polyfills/object-assign-polyfill'
import errorHandler from './lib/error-handler'
import { findAllVueComponentsFromVm } from './lib/find-vue-components'

Vue.config.productionTip = false
Vue.config.errorHandler = errorHandler
Expand All @@ -25,8 +26,10 @@ export default function mount (component: Component, options: Options = {}): Vue
vm.$mount()
}

if (vm._error) {
throw (vm._error)
const componentsWithError = findAllVueComponentsFromVm(vm).filter(c => c._error)

if (componentsWithError.length > 0) {
throw (componentsWithError[0]._error)
}

return new VueWrapper(vm, { attachedToDocument: !!options.attachToDocument })
Expand Down
22 changes: 21 additions & 1 deletion test/specs/mount.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,27 @@ describe('mount', () => {
}

const fn = () => mount(TestComponent)
expect(fn).to.throw()
expect(fn).to.throw('Error in mounted')
})

it('propagates errors when they are thrown by a nested component', () => {
const childComponent = {
template: '<div></div>',
mounted: function () {
throw new Error('Error in mounted')
}
}
const rootComponent = {
render: function (h) {
return h('div', [h(childComponent)])
}
}

const fn = () => {
mount(rootComponent)
}

expect(fn).to.throw('Error in mounted')
})

it('overwrites the component options with the options other than the mounting options when the options for mount contain those', () => {
Expand Down