Skip to content

fix: check for errors on child components #415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 8, 2018
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