Skip to content

Commit a06e253

Browse files
chriscasolaeddyerburgh
authored andcommitted
fix: check for errors on child components (#415)
1 parent a63e34d commit a06e253

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

src/lib/find-vue-components.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
throwError
99
} from './util'
1010

11-
function findAllVueComponentsFromVm (
11+
export function findAllVueComponentsFromVm (
1212
vm: Component,
1313
components: Array<Component> = []
1414
): Array<Component> {

src/mount.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import createElement from './lib/create-element'
88
import './lib/polyfills/matches-polyfill'
99
import './lib/polyfills/object-assign-polyfill'
1010
import errorHandler from './lib/error-handler'
11+
import { findAllVueComponentsFromVm } from './lib/find-vue-components'
1112

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

28-
if (vm._error) {
29-
throw (vm._error)
29+
const componentsWithError = findAllVueComponentsFromVm(vm).filter(c => c._error)
30+
31+
if (componentsWithError.length > 0) {
32+
throw (componentsWithError[0]._error)
3033
}
3134

3235
return new VueWrapper(vm, { attachedToDocument: !!options.attachToDocument })

test/specs/mount.spec.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,27 @@ describe('mount', () => {
175175
}
176176

177177
const fn = () => mount(TestComponent)
178-
expect(fn).to.throw()
178+
expect(fn).to.throw('Error in mounted')
179+
})
180+
181+
it('propagates errors when they are thrown by a nested component', () => {
182+
const childComponent = {
183+
template: '<div></div>',
184+
mounted: function () {
185+
throw new Error('Error in mounted')
186+
}
187+
}
188+
const rootComponent = {
189+
render: function (h) {
190+
return h('div', [h(childComponent)])
191+
}
192+
}
193+
194+
const fn = () => {
195+
mount(rootComponent)
196+
}
197+
198+
expect(fn).to.throw('Error in mounted')
179199
})
180200

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

0 commit comments

Comments
 (0)