Browse Source

options propsData tests

Evan You 10 years ago
parent
commit
2a09188e01

+ 14 - 7
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()
+  })
 })

+ 30 - 0
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: '<div>{{ a }}</div>'
+    })
+    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()
+  })
+})