-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathtest.js
89 lines (88 loc) · 2.05 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import {
jsdom
}
from 'jsdom'
global.document = jsdom('<!doctype html><html><body></body></html>')
global.window = document.defaultView
import Vue from 'vue'
import revue from './revue.common'
import store from './example/store'
import {
addTodo
} from './example/actions/todos'
Vue.use(revue, {
store
})
describe('main', () => {
it('dispatch ADDED_TODO', done => {
const vm = new Vue({
data() {
return {
todos: this.$store.state.todos
}
},
// do not use ready() here because the test now is not in dom environment
created() {
this.$subscribe('todos')
this.$store.dispatch({
type: 'ADDED_TODO',
text: 'hi'
})
}
})
vm.$data.todos.items[vm.$data.todos.items.length - 1].text.should.equal('hi')
done()
})
it('test native value', done => {
const vm = new Vue({
data() {
return {
count: this.$store.state.counter
}
},
created() {
this.$subscribe('counter as count')
this.$store.dispatch({
type: 'INCREMENT'
})
}
})
vm.$data.count.should.equal(1)
done()
})
it('test thunk', done => {
const vm = new Vue({
data() {
return {
todos: this.$store.state.todos
}
},
created() {
this.$subscribe('todos')
this.$store.dispatch(addTodo('meet a girl'))
}
})
setTimeout(() => {
vm.$data.todos.items[vm.$data.todos.items.length - 1].text.should.equal('meet a girl')
done()
}, 1000)
})
it('test deep property', done => {
const vm = new Vue({
data() {
return {
fakeAdmin: this.$store.state.admin
}
},
created() {
this.$subscribe('admin.info.name as fakeAdmin.info.name')
this.$store.dispatch({
type: 'CHANGE_NAME',
name: 'sox'
})
}
})
vm.$data.fakeAdmin.info.name.should.equal('sox')
done()
})
})