Skip to content

Commit

Permalink
test: add more test case for watch option
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jan 10, 2019
1 parent 8b382b3 commit 1e5174d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/util/lang.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions test/unit/features/component/component-scoped-slot.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 32 additions & 0 deletions test/unit/features/options/watch.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Vue from 'vue'
import testObjectOption from '../../../helpers/test-object-option'
import { finished } from 'stream';

describe('Options watch', () => {
let spy
Expand Down Expand Up @@ -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()
})
})

0 comments on commit 1e5174d

Please sign in to comment.