react-native-tab-view
react-native-tab-view copied to clipboard
Testing TabView with Jest doensn't working
Current behaviour
I want to test interactions on my different TabView scenes, e.g. click on a selectable Card and press a next Button to navigate to the next scene. But that isn't possible with Jest. All Scenes and Components (Buttons, Texts, ...) are returned as promsise in my jest / react-native-testing-library setup. I can expect them, e.g. expect(getByTestId(SOME_TEST_ID_IN_TABVIEW))
but when I access a Button and try to fire an event (fireEvent.press(SOME_BUTTON_IN_TABVIEW)
) I get the TypeError onPress of undefined
Expected behaviour
I want to test interactions on the different scenes, so it's necessary, that I can access all components in the rendered scenes.
Code sample
const ShuffleFilter = ({ navigateToHome }) => {
const filterRoutes = ['STEP_1', 'STEP_2', 'STEP_3', 'STEP_4', 'STEP_5']
const [tabState, setTabState] = useState({
index: 0,
routes: filterRoutes.map((key) => ({ key })),
})
const renderTabBar = (props) => {
return (
<FilterStepTabBarButton
tabProps={props}
tabState={tabState}
navigateToHome={navigateToHome}
/>
)
}
const renderScene = ({ route }) => {
return <FilterStep onPressClose={navigateToHome} step={route.key} />
}
return (
<SafeAreaView style={styles.body} testID={A11y.SHUFFLE_FILTER_VIEW}>
<TabView
swipeEnabled={false}
navigationState={tabState}
renderScene={renderScene}
renderTabBar={renderTabBar}
tabBarPosition="bottom"
onIndexChange={(index) => setTabState((state) => ({ ...state, index }))}
/>
</SafeAreaView>
)
}
What have you tried
I've tried to access them in different ways, await them etc.... nothing helped me. All inside my <TabView />
is handled as a promise.
Your Environment
software | version |
---|---|
ios or android | ios |
react | 16.13.1 |
react-native | 0.62.2 |
react-native-tab-view | ^2.14.4 |
react-native-gesture-handler | ^1.6.1 |
react-native-reanimated | ^1.9.0 |
node | 12.16.1 |
npm or yarn | yarn 1.22.0 |
I am also having trouble testing with jest. Has anyone found a guide or solution for testing Tabview?
same here
What have you tried
I've tried to access them in different ways, await them etc.... nothing helped me. All inside my
<TabView />
is handled as a promise.
@fuggerstadt1907 Did you find any solution to this? Any insight that may be helpful for people with same issue?
have anyone here found this fix or a workaround?
Did anyone found any solution for this?
No, unfortunately not so far 😞