Я использую Ant Design для своего компонента формы выбора, и я хотел бы проверить значение параметров, потому что значения будут динамически изменяться в зависимости от различных вариантов выбора, сделанных пользователем при заполнении.
my-test.spec.js
let questionDropdown
await waitFor(() => {
questionDropdown = screen.getByRole('combobox', { name: 'Question'})
expect(questionDropdown).toBeDefined()
})
fireEvent.click(questionDropdown)
// Hoping to test the options after clicking on the select, but I can't find the options element on screen
// expect(screen.getByText('question 1')).toBeDefined()
// expect(screen.queryAllByRole('option').length).toEqual(2)
Я обнаружил эти проблемы в antd
о том, как имитировать компоненты Select и Options.
jest.mock('antd', () => {
const antd = jest.requireActual('antd');
const Select = ({ children, onChange }) => {
return <select onChange={e => onChange(e.target.value)}>{children}</select>;
};
Select.Option = ({ children, ...otherProps }) => {
return <option {...otherProps}>{children}</option>;
}
return {
...antd,
Select,
}
}
, но мне все равно не удалось протестировать мои варианты.