Skip to content

Commit fd85fbc

Browse files
Brendan Strombergertimdorr
authored andcommitted
react-router-redux/createMatchSelector: handle null case when router state is not yet initialized (#5653)
* react-router-redux/createMatchSelector: handle null case when router state is not yet initialized * react-router-redux/createMatchSelector: test coverage for 4a826fa * tests/createMatchSelector: fixed assertion in test * Made test assertion a little more useful/semantic
1 parent d6ac814 commit fd85fbc

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

packages/react-router-redux/modules/__tests__/selectors-test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('selectors', () => {
2525
})
2626

2727
describe('createMatchSelector', () => {
28-
it('matches correctly', () => {
28+
it('matches correctly if the router is initialized', () => {
2929
const matchSelector = createMatchSelector('/')
3030
store.dispatch({
3131
type: LOCATION_CHANGE,
@@ -39,6 +39,12 @@ describe('selectors', () => {
3939
url: '/'
4040
})
4141
})
42+
43+
it('does not throw error if router has not yet initialized', () => {
44+
const matchSelector = createMatchSelector('/')
45+
const state = store.getState()
46+
expect(() => matchSelector(state)).not.toThrow()
47+
})
4248

4349
it('does not update if the match is the same', () => {
4450
const matchSelector = createMatchSelector('/')

packages/react-router-redux/modules/selectors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const createMatchSelector = (path) => {
66
let lastPathname = null
77
let lastMatch = null
88
return (state) => {
9-
const { pathname } = getLocation(state)
9+
const { pathname } = getLocation(state) || {}
1010
if (pathname === lastPathname) {
1111
return lastMatch
1212
}

0 commit comments

Comments
 (0)