UNPKG

1.88 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 './revue.common'
6import store from './example/store'
7import { addTodo } from './example/actions/todos'
8Vue.use(revue, {
9 store
10})
11
12describe('main', () => {
13 it('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 native value', done => {
29 const vm = new Vue({
30 data () {
31 return {
32 count: this.$revue.getState().counter
33 }
34 },
35 created () {
36 this.$subscribe('counter as count')
37 this.$revue.dispatch({type: 'INCREMENT'})
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: this.$revue.getState().todos
48 }
49 },
50 created () {
51 this.$subscribe('todos')
52 this.$revue.dispatch(addTodo('meet a girl'))
53 }
54 })
55 setTimeout(() => {
56 vm.$data.todos.items[vm.$data.todos.items.length - 1].text.should.equal('meet a girl')
57 done()
58 }, 1000)
59 })
60 it('test deep property', done => {
61 const vm = new Vue({
62 data () {
63 return {
64 fakeAdmin: this.$revue.getState().admin
65 }
66 },
67 created () {
68 this.$subscribe('admin.info.name as fakeAdmin.info.name')
69 this.$revue.dispatch({type: 'CHANGE_NAME', name: 'sox'})
70 }
71 })
72 vm.$data.fakeAdmin.info.name.should.equal('sox')
73 done()
74 })
75})