mirror of
https://gitee.com/vuejs/vue.git
synced 2024-12-04 04:57:40 +08:00
improve $props test case
This commit is contained in:
parent
87ffd0da9f
commit
4f6b1014b3
@ -80,20 +80,49 @@ describe('Instance properties', () => {
|
||||
expect(calls).toEqual(['outer:undefined', 'middle:outer', 'inner:middle', 'next:undefined'])
|
||||
})
|
||||
|
||||
it('$props', () => {
|
||||
var Comp = Vue.extend({
|
||||
it('$props', done => {
|
||||
const Comp = Vue.extend({
|
||||
props: ['msg'],
|
||||
template: '<div>{{ msg }}</div>'
|
||||
template: '<div>{{ msg }} {{ $props.msg }}</div>'
|
||||
})
|
||||
var vm = new Comp({
|
||||
const vm = new Comp({
|
||||
propsData: {
|
||||
msg: 'foo'
|
||||
}
|
||||
})
|
||||
}).$mount()
|
||||
// check render
|
||||
expect(vm.$el.textContent).toContain('foo foo')
|
||||
// warn set
|
||||
vm.$props = {}
|
||||
expect('$props is readonly').toHaveBeenWarned()
|
||||
// check existence
|
||||
expect(vm.$props.msg).toBe('foo')
|
||||
// check change
|
||||
Vue.set(vm, 'msg', 'bar')
|
||||
vm.msg = 'bar'
|
||||
expect(vm.$props.msg).toBe('bar')
|
||||
waitForUpdate(() => {
|
||||
expect(vm.$el.textContent).toContain('bar bar')
|
||||
}).then(() => {
|
||||
vm.$props.msg = 'baz'
|
||||
expect(vm.msg).toBe('baz')
|
||||
}).then(() => {
|
||||
expect(vm.$el.textContent).toContain('baz baz')
|
||||
}).then(done)
|
||||
})
|
||||
|
||||
it('warn mutating $props', () => {
|
||||
const Comp = {
|
||||
props: ['msg'],
|
||||
render () {},
|
||||
mounted () {
|
||||
expect(this.$props.msg).toBe('foo')
|
||||
this.$props.msg = 'bar'
|
||||
}
|
||||
}
|
||||
new Vue({
|
||||
template: `<comp ref="comp" msg="foo" />`,
|
||||
components: { Comp }
|
||||
}).$mount()
|
||||
expect(`Avoid mutating a prop`).toHaveBeenWarned()
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user