UNPKG

1.14 kBJavaScriptView Raw
1import { jsdom } from 'jsdom'
2global.document = jsdom('<!doctype html><html><body></body></html>')
3global.window = document.defaultView
4import Vue from 'vue'
5import revue from './lib/revue'
6import store from './lib/store'
7import { addTodo } from './lib/actions/todos'
8Vue.use(revue, {
9 store
10})
11
12describe('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})