-
Notifications
You must be signed in to change notification settings - Fork 140
/
Copy pathreducerParameters.js
61 lines (52 loc) · 1.37 KB
/
reducerParameters.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
import { createMemoryHistory } from 'rudy-history'
import { getInitialState } from '../src/reducer/createLocationReducer'
export default (type, pathname) => {
// eslint-disable-line import/prefer-default-export
const history = createMemoryHistory({ initialEntries: ['/first'] })
history.push(pathname)
const current = { pathname, type, payload: { param: 'bar' } }
const prev = { pathname: '/first', type: 'FIRST', payload: {} }
const routesMap = {
FIRST: '/first',
SECOND: '/second/:param'
}
return {
type,
pathname,
current,
prev,
initialState: getInitialState(
prev.pathname,
{},
prev.type,
prev.payload,
routesMap,
history
),
routesMap,
action: {
type,
payload: { param: 'bar' },
meta: {
location: {
current,
prev,
kind: 'load',
history: {
entries: history.entries.slice(0), // history.entries.map(entry => entry.pathname)
index: history.index,
length: history.length
}
}
}
},
expectState(state) {
expect(state.pathname).toEqual(pathname)
expect(state.type).toEqual(type)
expect(state.payload).toEqual({ param: 'bar' })
expect(state.prev).toEqual(prev)
expect(state.kind).toEqual('load')
expect(state).toMatchSnapshot()
}
}
}