Skip to content
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

fix: remove throw from errorHandler #655

Merged
merged 5 commits into from
Jun 1, 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
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