Skip to content

Commit

Permalink
fix: remove throw from errorHandler (#655)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyerburgh committed Jun 1, 2018
1 parent 9a2a25a commit b4517ab
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/test-utils/src/mount.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ import { addScopedSlots } from './add-scoped-slots'

Vue.config.productionTip = false
Vue.config.devtools = false
Vue.config.errorHandler = errorHandler

export default function mount (component: Component, options: Options = {}): VueWrapper {
const existingErrorHandler = Vue.config.errorHandler
Vue.config.errorHandler = errorHandler

warnIfNoWindow()

// Remove cached constructor
delete component._Ctor

const vueConstructor = options.localVue || createLocalVue()

const elm = options.attachToDocument
Expand Down Expand Up @@ -57,6 +62,8 @@ export default function mount (component: Component, options: Options = {}): Vue
throw (componentsWithError[0]._error)
}

Vue.config.errorHandler = existingErrorHandler

const wrapperOptions = {
attachedToDocument: !!mergedOptions.attachToDocument,
sync: mergedOptions.sync
Expand Down
34 changes: 34 additions & 0 deletions test/specs/mount.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,40 @@ describeRunIf(process.env.TEST_ENV !== 'node',
expect(fn).to.throw('Error in mounted')
})

itDoNotRunIf(
vueVersion < 2.2,
'logs errors once after mount', (done) => {
Vue.config.errorHandler = null
const TestComponent = {
template: '<div/>',
updated: function () {
throw new Error('Error in updated')
}
}

const wrapper = mount(TestComponent, {
sync: false
})
wrapper.vm.$forceUpdate()
setTimeout(() => {
vueVersion > 2.1
? expect(console.error).calledTwice
: expect(console.error).calledOnce
done()
})
})

it('restores user error handler after mount', () => {
const existingErrorHandler = () => {}
Vue.config.errorHandler = existingErrorHandler
const TestComponent = {
template: '<div/>'
}
mount(TestComponent)
expect(Vue.config.errorHandler).to.equal(existingErrorHandler)
Vue.config.errorHandler = null
})

it('overwrites the component options with the options other than the mounting options when the options for mount contain those', () => {
const Component = {
template: '<div>{{ foo() }}{{ bar() }}{{ baz() }}</div>',
Expand Down

0 comments on commit b4517ab

Please sign in to comment.