Open mateen-hussain opened 6 years ago
I'm unable to simulate an onDateChange or onPress event to test my component.
Component
<View style={styles.datePickerCard}> <Text h4 style={styles.cardHeader}>Pick a Date</Text> <DatePicker mode="date" placeholder="select date" date={selectedDateLocal} format="LL" minDate={new Date()} confirmBtnText="Confirm" cancelBtnText="Cancel" androidMode="calendar" onDateChange={(date) => { setSelectedDate(CentreId, date); }} customStyles={{ btnTextConfirm: { color: primaryColor, }, btnTextCancel: { color: secondaryColor, }, dateInput: { height: 40, borderWidth: 0, width: 500, }, }} style={styles.datePicker} /> </View>
Jest
// act const tree = shallow(<DatePickerCard setSelectedDate={setSelectedDate} CentreId={CentreId} selectedDateLocal={selectedDateLocal} />); const datePicker = tree.find('DatePicker').simulate('onPressConfirm'); expect(setSelectedDate).toHaveBeenCalledTimes(1); });
react
react-native -v
I think simulate only trigger event. You can call the onPressConfirm function directly with the instance.
simulate
onPressConfirm
Issue
I'm unable to simulate an onDateChange or onPress event to test my component.
Expected Behavior
Javascript
Component
Jest
Environment
react
: "^16.0.0-beta.5"react-native -v
: ^0.49.5