diff --git a/test/unit/features/instance/properties.spec.js b/test/unit/features/instance/properties.spec.js index 251a3088..e74a1ca1 100644 --- a/test/unit/features/instance/properties.spec.js +++ b/test/unit/features/instance/properties.spec.js @@ -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: '
{{ msg }}
' + template: '
{{ msg }} {{ $props.msg }}
' }) - 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: ``, + components: { Comp } + }).$mount() + expect(`Avoid mutating a prop`).toHaveBeenWarned() }) })