From 2a09188e016cb7bbc10c8e09079cd66024a448c0 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 29 May 2016 14:28:03 -0400 Subject: [PATCH] options propsData tests --- test/unit/features/options/data.spec.js | 21 +++++++++----- test/unit/features/options/propsData.spec.js | 30 ++++++++++++++++++++ 2 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 test/unit/features/options/propsData.spec.js diff --git a/test/unit/features/options/data.spec.js b/test/unit/features/options/data.spec.js index 4c25df37..3d2fc7b2 100644 --- a/test/unit/features/options/data.spec.js +++ b/test/unit/features/options/data.spec.js @@ -15,13 +15,6 @@ describe('Options data', () => { }).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 () { @@ -60,4 +53,18 @@ describe('Options data', () => { expect(vm.obj.a).toBe(1) expect(vm.obj.b).toBe(2) }) + + it('should warn non-function during extend', () => { + Vue.extend({ + data: { msg: 'foo' } + }) + expect('The "data" option should be a function').toHaveBeenWarned() + }) + + it('should warn non object return', () => { + new Vue({ + data () {} + }) + expect('data functions should return an object').toHaveBeenWarned() + }) }) diff --git a/test/unit/features/options/propsData.spec.js b/test/unit/features/options/propsData.spec.js new file mode 100644 index 00000000..9fa5557e --- /dev/null +++ b/test/unit/features/options/propsData.spec.js @@ -0,0 +1,30 @@ +import Vue from 'vue' + +describe('Options propsData', () => { + it('should work', done => { + const A = Vue.extend({ + props: ['a'], + template: '
{{ a }}
' + }) + const vm = new A({ + propsData: { + a: 123 + } + }).$mount() + expect(vm.a).toBe(123) + expect(vm.$el.textContent).toBe('123') + vm.a = 234 + waitForUpdate(() => { + expect(vm.$el.textContent).toBe('234') + }).then(done) + }) + + it('warn non instantiation usage', () => { + Vue.extend({ + propsData: { + a: 123 + } + }) + expect('option "propsData" can only be used during instance creation').toHaveBeenWarned() + }) +})