Просмотр исходного кода

feat: rename catchError -> errorCaptured

Evan You 8 лет назад
Родитель
Сommit
6dac3dbe44
2 измененных файлов с 9 добавлено и 9 удалено
  1. 3 3
      src/core/util/error.js
  2. 6 6
      test/unit/features/options/errorCaptured.spec.js

+ 3 - 3
src/core/util/error.js

@@ -8,12 +8,12 @@ export function handleError (err: Error, vm: any, info: string) {
   if (vm) {
     let cur = vm
     while ((cur = cur.$parent)) {
-      if (cur.$options.catchError) {
+      if (cur.$options.errorCaptured) {
         try {
-          const propagate = cur.$options.catchError.call(cur, err, vm, info)
+          const propagate = cur.$options.errorCaptured.call(cur, err, vm, info)
           if (!propagate) return
         } catch (e) {
-          globalHandleError(e, cur, 'catchError')
+          globalHandleError(e, cur, 'errorCaptured hook')
         }
       }
     }

+ 6 - 6
test/unit/features/options/catchError.spec.js → test/unit/features/options/errorCaptured.spec.js

@@ -1,6 +1,6 @@
 import Vue from 'vue'
 
-describe('Options catchError', () => {
+describe('Options errorCaptured', () => {
   let globalSpy
 
   beforeEach(() => {
@@ -26,7 +26,7 @@ describe('Options catchError', () => {
     }
 
     new Vue({
-      catchError: spy,
+      errorCaptured: spy,
       render: h => h(Child)
     }).$mount()
 
@@ -49,7 +49,7 @@ describe('Options catchError', () => {
       data: {
         error: null
       },
-      catchError (e, vm, info) {
+      errorCaptured (e, vm, info) {
         expect(vm).toBe(child)
         this.error = e.toString() + ' in ' + info
       },
@@ -82,7 +82,7 @@ describe('Options catchError', () => {
     }
 
     new Vue({
-      catchError (err, vm, info) {
+      errorCaptured (err, vm, info) {
         spy(err, vm, info)
         return true
       },
@@ -108,7 +108,7 @@ describe('Options catchError', () => {
 
     let err2
     const vm = new Vue({
-      catchError () {
+      errorCaptured () {
         err2 = new Error('foo')
         throw err2
       },
@@ -116,6 +116,6 @@ describe('Options catchError', () => {
     }).$mount()
 
     expect(globalSpy).toHaveBeenCalledWith(err, child, 'created hook')
-    expect(globalSpy).toHaveBeenCalledWith(err2, vm, 'catchError')
+    expect(globalSpy).toHaveBeenCalledWith(err2, vm, 'errorCaptured hook')
   })
 })