mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-04-29 21:05:29 +08:00
This reverts commit 5febb81a1c.
This commit is contained in:
@@ -76,4 +76,43 @@ describe('addNavigationHelpers', () => {
|
|||||||
});
|
});
|
||||||
expect(mockedDispatch.mock.calls.length).toBe(1);
|
expect(mockedDispatch.mock.calls.length).toBe(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('handles GetParams action', () => {
|
||||||
|
const mockedDispatch = jest
|
||||||
|
.fn(() => false)
|
||||||
|
.mockImplementationOnce(() => true);
|
||||||
|
expect(
|
||||||
|
addNavigationHelpers({
|
||||||
|
state: { key: 'B', routeName: 'Settings', params: { name: 'Peter' } },
|
||||||
|
dispatch: mockedDispatch,
|
||||||
|
addListener: dummyEventSubscriber,
|
||||||
|
}).getParam('name', 'Brent')
|
||||||
|
).toEqual('Peter');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles GetParams action with default param', () => {
|
||||||
|
const mockedDispatch = jest
|
||||||
|
.fn(() => false)
|
||||||
|
.mockImplementationOnce(() => true);
|
||||||
|
expect(
|
||||||
|
addNavigationHelpers({
|
||||||
|
state: { key: 'B', routeName: 'Settings' },
|
||||||
|
dispatch: mockedDispatch,
|
||||||
|
addListener: dummyEventSubscriber,
|
||||||
|
}).getParam('name', 'Brent')
|
||||||
|
).toEqual('Brent');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles GetParams action with param value as null', () => {
|
||||||
|
const mockedDispatch = jest
|
||||||
|
.fn(() => false)
|
||||||
|
.mockImplementationOnce(() => true);
|
||||||
|
expect(
|
||||||
|
addNavigationHelpers({
|
||||||
|
state: { key: 'B', routeName: 'Settings', params: { name: null } },
|
||||||
|
dispatch: mockedDispatch,
|
||||||
|
addListener: dummyEventSubscriber,
|
||||||
|
}).getParam('name')
|
||||||
|
).toEqual(null);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -61,6 +61,16 @@ export default function(navigation) {
|
|||||||
return navigation.dispatch(NavigationActions.setParams({ params, key }));
|
return navigation.dispatch(NavigationActions.setParams({ params, key }));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getParam: (paramName, defaultValue) => {
|
||||||
|
const params = navigation.state.params;
|
||||||
|
|
||||||
|
if (params && paramName in params) {
|
||||||
|
return params[paramName];
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultValue;
|
||||||
|
},
|
||||||
|
|
||||||
push: (routeName, params, action) =>
|
push: (routeName, params, action) =>
|
||||||
navigation.dispatch(
|
navigation.dispatch(
|
||||||
NavigationActions.push({ routeName, params, action })
|
NavigationActions.push({ routeName, params, action })
|
||||||
|
|||||||
@@ -98,6 +98,7 @@ exports[`StackNavigator applies correct values when headerRight is present 1`] =
|
|||||||
Object {
|
Object {
|
||||||
"addListener": [Function],
|
"addListener": [Function],
|
||||||
"dispatch": [Function],
|
"dispatch": [Function],
|
||||||
|
"getParam": [Function],
|
||||||
"goBack": [Function],
|
"goBack": [Function],
|
||||||
"navigate": [Function],
|
"navigate": [Function],
|
||||||
"pop": [Function],
|
"pop": [Function],
|
||||||
@@ -337,6 +338,7 @@ exports[`StackNavigator renders successfully 1`] = `
|
|||||||
Object {
|
Object {
|
||||||
"addListener": [Function],
|
"addListener": [Function],
|
||||||
"dispatch": [Function],
|
"dispatch": [Function],
|
||||||
|
"getParam": [Function],
|
||||||
"goBack": [Function],
|
"goBack": [Function],
|
||||||
"navigate": [Function],
|
"navigate": [Function],
|
||||||
"pop": [Function],
|
"pop": [Function],
|
||||||
|
|||||||
Reference in New Issue
Block a user