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 revue from './lib/revue'
|
6 | import store from './lib/store'
|
7 | import { addTodo } from './lib/actions/todos'
|
8 | Vue.use(revue, {
|
9 | store
|
10 | })
|
11 |
|
12 | describe('main', () => {
|
13 | it('should dispatch ADDED_TODO', done => {
|
14 | const vm = new Vue({
|
15 | data () {
|
16 | return {
|
17 | todos: this.$revue.getState().todos
|
18 | }
|
19 | },
|
20 | created () {
|
21 | this.$subscribe('todos')
|
22 | this.$revue.dispatch({type: 'ADDED_TODO', text: 'hi'})
|
23 | }
|
24 | })
|
25 | vm.$data.todos.items[vm.$data.todos.items.length - 1].text.should.equal('hi')
|
26 | done()
|
27 | })
|
28 | it('test thunk', done => {
|
29 | const vm = new Vue({
|
30 | data () {
|
31 | return {
|
32 | todos: this.$revue.getState().todos
|
33 | }
|
34 | },
|
35 | created () {
|
36 | this.$subscribe('todos')
|
37 | this.$revue.dispatch(addTodo('meet a girl'))
|
38 | }
|
39 | })
|
40 | setTimeout(() => {
|
41 | vm.$data.todos.items[vm.$data.todos.items.length - 1].text.should.equal('meet a girl')
|
42 | done()
|
43 | }, 1000)
|
44 | })
|
45 | })
|