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

test: add more test case for watch option

Evan You 7 лет назад
Родитель
Сommit
1e5174d213

+ 1 - 1
src/core/util/lang.js

@@ -30,7 +30,7 @@ export function def (obj: Object, key: string, val: any, enumerable?: boolean) {
 /**
  * Parse simple path.
  */
-const bailRE = new RegExp(`[^${unicodeLetters}.$_]`)
+const bailRE = new RegExp(`[^${unicodeLetters}.$_\\d]`)
 export function parsePath (path: string): any {
   if (bailRE.test(path)) {
     return

+ 6 - 0
test/unit/features/component/component-scoped-slot.spec.js

@@ -689,5 +689,11 @@ describe('Component scoped slot', () => {
       }).$mount()
       expect(vm.$el.innerHTML).toBe(`default<div>default</div><div>static</div>`)
     })
+
+    it('should not break when template expression uses $slots', () => {
+      const vm = new Vue({
+        template: ``
+      })
+    })
   })
 })

+ 32 - 0
test/unit/features/options/watch.spec.js

@@ -1,5 +1,6 @@
 import Vue from 'vue'
 import testObjectOption from '../../../helpers/test-object-option'
+import { finished } from 'stream';
 
 describe('Options watch', () => {
   let spy
@@ -143,4 +144,35 @@ describe('Options watch', () => {
       expect(spy3).toHaveBeenCalledWith(1, 0)
     }).then(done)
   })
+
+  it('should support watching unicode paths', done => {
+    const vm = new Vue({
+      data: {
+        数据: 1
+      },
+      watch: {
+        数据: spy
+      }
+    })
+    expect(spy).not.toHaveBeenCalled()
+    vm['数据'] = 2
+    expect(spy).not.toHaveBeenCalled()
+    waitForUpdate(() => {
+      expect(spy).toHaveBeenCalledWith(2, 1)
+    }).then(done)
+  })
+
+  it('should not warn proper usage', () => {
+    const vm = new Vue({
+      data: {
+        foo: { _bar: 1 }, // element has such watchers...
+        prop1: 123
+      },
+      watch: {
+        'foo._bar': () => {},
+        prop1 () {}
+      }
+    })
+    expect(`Failed watching path`).not.toHaveBeenWarned()
+  })
 })