我正在尝试测试两个屏幕之间的简单导航流程。我有我的LandingScreen:
class LandingScreen extends Component {
constructor(props){
super(props);
}
handleNavigation = () => {
this.props.navigation.navigate('AgeScreen');
}
render() {
return (
<View>
//extra UI components
<TouchableOpacity onPress={this.handleNavigation}>
<View style={styles.buttonWrapper}>
//extra UI components
</View>
</TouchableOpacity>
</View>
)
}
}
export default LandingScreen;
单击handleNavigation
时,我希望显示AgeScreen
。我手动进行了测试,它可以工作;但是,我也想向其中添加一个单元测试。
这是我到目前为止编写的单元测试:
describe('Testing navigation', () => {
it('Navigates as expected', () => {
let handleNavigationMock = jest.fn()
const navigation = { navigate: jest.fn() };
let landingScreen = renderer.create(
<LandingScreen
handleNavigation={navigation}
navigation={navigation}
/>
).getInstance()
landingScreen.handleNavigation();
expect(handleNavigationMock).toBeCalled();
});
});
我的问题是测试失败,并显示以下消息:
Expected number of calls: >= 1
Received number of calls: 0
我的问题是:
任何帮助将不胜感激!