Reactjs 使用Jest&;测试DateTimePickerModel;React本机测试库
我正在尝试使用Jest和。我通过了3项(我认为是)标准RN道具:Reactjs 使用Jest&;测试DateTimePickerModel;React本机测试库,reactjs,react-native,jestjs,expo,react-native-testing-library,Reactjs,React Native,Jestjs,Expo,React Native Testing Library,我正在尝试使用Jest和。我通过了3项(我认为是)标准RN道具: accessible: true, accessibilityLabel: testLabel, testID: testLabel, 以下是我的测试: fireEvent(dobField, 'handleCalendarPress'); const calendarPicker = wrapper.getByTestId('BDD--ThirdPartyComp--DateTimePickerModal'); fireEve
accessible: true,
accessibilityLabel: testLabel,
testID: testLabel,
以下是我的测试:
fireEvent(dobField, 'handleCalendarPress');
const calendarPicker = wrapper.getByTestId('BDD--ThirdPartyComp--DateTimePickerModal');
fireEvent(calendarPicker, 'onConfirm', ageOver18);
dobField
是我创建的自定义输入字段,当它被“按下”时,我可以通过我添加的testID
找到模态。但是,第三个条件触发事件到onConfirm
,我得到以下错误:
Error: Uncaught [TypeError: this._picker.current.setNativeProps is not a function]
我已经阅读了关于“直接操作”的RN文档(),其中讨论了如何设置/使用本机道具
。然而,这似乎是应该在modal/lib本身上实现的东西,而不是从我的角度
因此,我的问题是:
我正在使用
react native datepicker
并得到相同的结果。_picker.setNativeProps不是函数
错误。我用mockdatepickeros
修复了它,因为react-native-datepicker
将datepickeros
用于IOS日期选择器
jest.mock('react-native/Libraries/Components/DatePicker/DatePickerIOS.ios.js', () => {
const React = require('React');
return class MockPicker extends React.Component {
render() {
return React.createElement('DatePicker', {date: '21.07.2020'});
}
};
});
你有没有找到解决问题的办法?我遇到了与我的一些测试类似的事情,我没有。我向开发人员提交了一个问题,他回答说:“老实说,我已经多年没有积极使用和测试这个库了,所以我不确定什么测试策略是最好的。在后台,此库使用@react native community/datetimepicker。您是否介意检查该库本身是否可测试,或者该问题是否仅发生在该组件上这一反应可追溯到2020年2月初。我们最终不再使用这个包,因为前端单元和自动化测试(Appium)都无法与它交互。