You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The native Link does not call onPress when passed because it is overridden in order to provide its routing functionality.
I would expect it to behave more like the react-router-dom Link and call the onPress function if it is passed. The docs state that all props would be passed to the rendered component, but onPress is not.
To fix, either the documentation should be updated to correctly describe the current behavior, or the component should be updated to adhere to the documentation.
I'd be happy to submit a pull request, or here's a failing test to get you started.
importReactfrom'react'importReactTestUtilsfrom'react-addons-test-utils'import{View}from'react-native'importLinkfrom'../Link'constcreateContext=()=>({router: {history: {push: jest.fn(),replace: jest.fn()}}})describe('<Link />',()=>{it('calls onPress when pressed',()=>{constrenderer=ReactTestUtils.createRenderer()constonPress=jest.fn()constcontext=createContext()renderer.render(<LinkonPress={onPress}to='/'><View/></Link>,context)constoutput=renderer.getRenderOutput()output.props.onPress()// simulate onPress on TouchableHighlightexpect(onPress.mock.calls.length).toBe(1)})})
The text was updated successfully, but these errors were encountered:
The change is simple, but a couple of quick questions:
Should the event.preventDefault behavior of react-router-dom/Link be preserved here? (ie: if user prevents default in their onPress handler, react-router does nothing)
Should any tests be done with jest? I noticed that only react-router-native uses jest as a testing framework, and I don't know if consistency across packages is a goal.
Yes, you should respect the event bubbling wishes of an onPress handler.
react-router-redux uses jest too (it also uses rollup for UMD builds). Use whatever testing framework is already established. Jest is built into RN, hence we used it for that sub-package.
The native Link does not call onPress when passed because it is overridden in order to provide its routing functionality.
I would expect it to behave more like the react-router-dom Link and call the onPress function if it is passed. The docs state that all props would be passed to the rendered component, but onPress is not.
To fix, either the documentation should be updated to correctly describe the current behavior, or the component should be updated to adhere to the documentation.
I'd be happy to submit a pull request, or here's a failing test to get you started.
The text was updated successfully, but these errors were encountered: