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