File tree Expand file tree Collapse file tree 2 files changed +9
-1
lines changed
Expand file tree Collapse file tree 2 files changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -2,10 +2,17 @@ import deepFreeze from 'deep-freeze';
22
33import { INITIAL_FETCH_COMPLETE } from '../../actionConstants' ;
44import navReducer , { getStateForRoute } from '../navReducer' ;
5+ import NavigationService from '../NavigationService' ;
56
67describe ( 'navReducer' , ( ) => {
78 describe ( 'INITIAL_FETCH_COMPLETE' , ( ) => {
89 test ( 'do not mutate navigation state if already at the same route' , ( ) => {
10+ NavigationService . getState = jest . fn ( ) . mockReturnValue (
11+ deepFreeze ( {
12+ index : 0 ,
13+ routes : [ { routeName : 'main' } ] ,
14+ } ) ,
15+ ) ;
916 const prevState = getStateForRoute ( 'main' ) ;
1017
1118 const action = deepFreeze ( {
Original file line number Diff line number Diff line change 22import type { NavigationAction } from 'react-navigation' ;
33
44import type { NavigationState , Action } from '../types' ;
5+ import { getCurrentRouteName } from './navSelectors' ;
56import AppNavigator from './AppNavigator' ;
67import { INITIAL_FETCH_COMPLETE } from '../actionConstants' ;
78
@@ -29,7 +30,7 @@ export const initialState = getStateForRoute('loading');
2930export default ( state : NavigationState = initialState , action : Action ) : NavigationState => {
3031 switch ( action . type ) {
3132 case INITIAL_FETCH_COMPLETE :
32- return state . routes [ 0 ] . routeName === 'main' ? state : getStateForRoute ( 'main' ) ;
33+ return getCurrentRouteName ( ) === 'main' ? state : getStateForRoute ( 'main' ) ;
3334
3435 default : {
3536 // The `react-navigation` libdef says this only takes a NavigationAction,
You can’t perform that action at this time.
0 commit comments