Skip to content
This repository was archived by the owner on Oct 26, 2018. It is now read-only.

Commit def06ff

Browse files
committed
Add reducer tests. Ensure actions are FSA.
1 parent 379dc9c commit def06ff

File tree

3 files changed

+63
-3
lines changed

3 files changed

+63
-3
lines changed

src/reducer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ const initialState = {
1414
* if you have asynchronously-loaded routes, so reading from and relying on
1515
* this state it is discouraged.
1616
*/
17-
export function routerReducer(state = initialState, { type, locationBeforeTransitions }) {
17+
export function routerReducer(state = initialState, { type, payload }) {
1818
if (type === LOCATION_CHANGE) {
19-
return { ...state, locationBeforeTransitions }
19+
return { ...state, locationBeforeTransitions: payload }
2020
}
2121

2222
return state

src/sync.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ export default function syncHistoryWithStore(history, store, {
8989
// Tell the store to update by dispatching an action
9090
store.dispatch({
9191
type: LOCATION_CHANGE,
92-
locationBeforeTransitions: location
92+
payload: location
9393
})
9494
}
9595
unsubscribeFromHistory = history.listen(handleLocationChange)

test/node/reducer.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/* eslint-env mocha */
2+
3+
import expect from 'expect'
4+
5+
import { LOCATION_CHANGE, routerReducer } from '../../src/reducer'
6+
7+
describe('routerReducer', () => {
8+
const state = {
9+
locationBeforeTransitions: {
10+
pathname: '/foo',
11+
action: 'POP'
12+
}
13+
}
14+
15+
it('updates the path', () => {
16+
expect(routerReducer(state, {
17+
type: LOCATION_CHANGE,
18+
payload: {
19+
path: '/bar',
20+
action: 'PUSH'
21+
}
22+
})).toEqual({
23+
locationBeforeTransitions: {
24+
path: '/bar',
25+
action: 'PUSH'
26+
}
27+
})
28+
})
29+
30+
it('works with initialState', () => {
31+
expect(routerReducer(undefined, {
32+
type: LOCATION_CHANGE,
33+
payload: {
34+
path: '/bar',
35+
action: 'PUSH'
36+
}
37+
})).toEqual({
38+
locationBeforeTransitions: {
39+
path: '/bar',
40+
action: 'PUSH'
41+
}
42+
})
43+
})
44+
45+
46+
it('respects replace', () => {
47+
expect(routerReducer(state, {
48+
type: LOCATION_CHANGE,
49+
payload: {
50+
path: '/bar',
51+
action: 'REPLACE'
52+
}
53+
})).toEqual({
54+
locationBeforeTransitions: {
55+
path: '/bar',
56+
action: 'REPLACE'
57+
}
58+
})
59+
})
60+
})

0 commit comments

Comments
 (0)