UNPKG

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