diff --git a/src/core/util/options.js b/src/core/util/options.js index f49c8236..c3618d31 100644 --- a/src/core/util/options.js +++ b/src/core/util/options.js @@ -285,11 +285,6 @@ export function mergeOptions ( normalizeComponents(child) normalizeProps(child) normalizeDirectives(child) - if (process.env.NODE_ENV !== 'production') { - if (child.propsData && !vm) { - warn('propsData can only be used as an instantiation option.') - } - } const extendsFrom = child.extends if (extendsFrom) { parent = typeof extendsFrom === 'function' diff --git a/test/unit/features/options/data.spec.js b/test/unit/features/options/data.spec.js index e69de29b..4c25df37 100644 --- a/test/unit/features/options/data.spec.js +++ b/test/unit/features/options/data.spec.js @@ -0,0 +1,63 @@ +import Vue from 'vue' + +describe('Options data', () => { + it('should proxy and be reactive', done => { + const data = { msg: 'foo' } + const vm = new Vue({ + data, + template: '
{{ msg }}
' + }).$mount() + expect(vm.$data).toEqual({ msg: 'foo' }) + expect(vm.$data).toBe(data) + data.msg = 'bar' + waitForUpdate(() => { + expect(vm.$el.textContent).toBe('bar') + }).then(done) + }) + + it('should warn non-function during extend', () => { + Vue.extend({ + data: { msg: 'foo' } + }) + expect('The "data" option should be a function').toHaveBeenWarned() + }) + + it('should merge data properly', () => { + const Test = Vue.extend({ + data () { + return { a: 1 } + } + }) + let vm = new Test({ + data: { b: 2 } + }) + expect(vm.a).toBe(1) + expect(vm.b).toBe(2) + // no instance data + vm = new Test() + expect(vm.a).toBe(1) + // no child-val + const Extended = Test.extend({}) + vm = new Extended() + expect(vm.a).toBe(1) + // recursively merge objects + const WithObject = Vue.extend({ + data () { + return { + obj: { + a: 1 + } + } + } + }) + vm = new WithObject({ + data: { + obj: { + b: 2 + } + } + }) + expect(vm.obj.a).toBe(1) + expect(vm.obj.b).toBe(2) + }) +})