Skip to content

Commit 2a09188

Browse files
committed
options propsData tests
1 parent ed10dcf commit 2a09188

2 files changed

Lines changed: 44 additions & 7 deletions

File tree

test/unit/features/options/data.spec.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@ describe('Options data', () => {
1515
}).then(done)
1616
})
1717

18-
it('should warn non-function during extend', () => {
19-
Vue.extend({
20-
data: { msg: 'foo' }
21-
})
22-
expect('The "data" option should be a function').toHaveBeenWarned()
23-
})
24-
2518
it('should merge data properly', () => {
2619
const Test = Vue.extend({
2720
data () {
@@ -60,4 +53,18 @@ describe('Options data', () => {
6053
expect(vm.obj.a).toBe(1)
6154
expect(vm.obj.b).toBe(2)
6255
})
56+
57+
it('should warn non-function during extend', () => {
58+
Vue.extend({
59+
data: { msg: 'foo' }
60+
})
61+
expect('The "data" option should be a function').toHaveBeenWarned()
62+
})
63+
64+
it('should warn non object return', () => {
65+
new Vue({
66+
data () {}
67+
})
68+
expect('data functions should return an object').toHaveBeenWarned()
69+
})
6370
})
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import Vue from 'vue'
2+
3+
describe('Options propsData', () => {
4+
it('should work', done => {
5+
const A = Vue.extend({
6+
props: ['a'],
7+
template: '<div>{{ a }}</div>'
8+
})
9+
const vm = new A({
10+
propsData: {
11+
a: 123
12+
}
13+
}).$mount()
14+
expect(vm.a).toBe(123)
15+
expect(vm.$el.textContent).toBe('123')
16+
vm.a = 234
17+
waitForUpdate(() => {
18+
expect(vm.$el.textContent).toBe('234')
19+
}).then(done)
20+
})
21+
22+
it('warn non instantiation usage', () => {
23+
Vue.extend({
24+
propsData: {
25+
a: 123
26+
}
27+
})
28+
expect('option "propsData" can only be used during instance creation').toHaveBeenWarned()
29+
})
30+
})

0 commit comments

Comments
 (0)