forked from mirrorjs/mirror
-
Notifications
You must be signed in to change notification settings - Fork 0
/
render.spec.js
88 lines (63 loc) · 1.76 KB
/
render.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import React from 'react'
import mirror, { actions, render, connect } from 'index'
import { store } from 'store'
describe('the render function', () => {
it('should create the store', () => {
const container = document.createElement('div')
mirror.model({
name: 'foo',
initialState: {
count: 0
}
})
render(<div/>, container)
expect(store).toBeDefined()
expect(store.getState).toBeInstanceOf(Function)
expect(store.getState().foo).toEqual({ count: 0 })
})
it('should connect and render', () => {
const container = document.createElement('div')
mirror.model({
name: 'app',
initialState: {
count: 1
},
reducers: {
increment(state) {
return { ...state, count: state.count + 1 }
}
}
})
/* eslint react/prop-types: 0 */
const Comp = props => <div id="app" onClick={actions.app.increment}>{props.count}</div>
const App = connect(({ app }) => app)(Comp)
render(<App/>, container)
const app = container.querySelector('#app')
expect(app.textContent).toEqual('1')
// call the action
actions.app.increment()
expect(app.textContent).toEqual('2')
})
it('should inject models dynamically', () => {
const container = document.createElement('div')
mirror.model({
name: 'model1',
initialState: {
count: 0
}
})
render(<div/>, container)
expect(store.getState().model1).toEqual({ count: 0 })
// create another model
mirror.model({
name: 'model2',
initialState: {
foo: 'foo'
}
})
// re-render
render()
expect(store.getState().model1).toEqual({ count: 0 })
expect(store.getState().model2).toEqual({ foo: 'foo' })
})
})