I'm trying to test my Select component from Native Base and in the test I select an item from the list or directly trigger the onValueChange
prop with a value and then assert the selected value, but I can't find the prop that holds the selected value, I've tried debugging, logging the component but I can't see what prop holds the value, it's supposed to be selectedValue
but I can't get to it.
A short snippet of my select that's managed by React Hook Forms and my test that uses React Native Testing Library and Jest
<Controller
control={control}
render={({ field: { onChange, onBlur, value } }) => (
<Select
selectedValue={value}
onValueChange={onChange}
minWidth='200'
accessibilityLabel={t('typePlaceholder')}
placeholder={t('typePlaceholder')}
_selectedItem={{
bg: 'teal.600',
endIcon: <CheckIcon size={5} />,
}}
mt='1'
testID='type-select'
>
{FUTURE_EXPENSE_TYPE_LIST.map(({ id, label, type }) => (
<Select.Item
label={t(label)}
value={type}
key={id}
testID={`${label}-id`}
/>
))}
</Select>
)}
name='type'
/>
My test:
it.only('test', async () => {
const futureExpensesAndGoalsPage = defaultNativeBaseWrapper(
<FutureExpensesAndGoals />
);
fireEvent.press(
futureExpensesAndGoalsPage.getByText(
'enableFutureExpenseAndGoalsFormButtonLabel'
)
);
fireEvent(
futureExpensesAndGoalsPage.getByPlaceholderText('typePlaceholder'),
'onValueChange',
'goals'
);
expect(
futureExpensesAndGoalsPage.getByPlaceholderText('typePlaceholder').props
.value
).toBe('goals');
futureExpensesAndGoalsPage.debug();
console.log(
'test',
futureExpensesAndGoalsPage.getByTestId('debt-id').props
);
});