forked from zhangyu921/mirror
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.spec.js
111 lines (81 loc) · 2.38 KB
/
router.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import React from 'react'
import PropTypes from 'prop-types'
import mirror, { actions, render, Router } from 'index'
import { history } from 'router'
beforeEach(() => {
jest.resetModules()
})
describe('the enhanced Router', () => {
let rootContext
const ContextChecker = (props, context) => {
rootContext = context
return null
}
ContextChecker.contextTypes = {
router: PropTypes.shape({
history: PropTypes.object,
route: PropTypes.object
})
}
afterEach(() => {
rootContext = undefined
})
it('should pass history to Router', () => {
const container = document.createElement('div')
render(
<Router>
<ContextChecker/>
</Router>,
container
)
expect(rootContext.router.history).toBe(history)
})
it('should add navigation methods of history object to actions.routing', () => {
const container = document.createElement('div')
mirror.defaults({
historyMode: 'hash'
})
render(
<Router>
<ContextChecker/>
</Router>,
container
)
expect(actions.routing).toBeDefined()
expect(actions.routing.push).toBeInstanceOf(Function)
expect(actions.routing.replace).toBeInstanceOf(Function)
expect(actions.routing.go).toBeInstanceOf(Function)
expect(actions.routing.goForward).toBeInstanceOf(Function)
expect(actions.routing.goBack).toBeInstanceOf(Function)
})
it('should change history when call methods in actions.routing', () => {
const container = document.createElement('div')
mirror.defaults({
historyMode: 'memory'
})
render(
<Router>
<ContextChecker/>
</Router>,
container
)
expect(rootContext.router.route.match.isExact).toBe(true)
actions.routing.push('/new')
expect(rootContext.router.route.match.isExact).toBe(false)
})
it('should be ok if pass an history object', () => {
const createHashHistory = require('history/createHashHistory').default
const _history = createHashHistory()
const container = document.createElement('div')
render(
<Router history={_history}>
<ContextChecker/>
</Router>,
container
)
expect(rootContext.router.history).toBe(_history)
expect(rootContext.router.route.match.isExact).toBe(true)
actions.routing.push('/new')
expect(rootContext.router.route.match.isExact).toBe(false)
})
})