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