I am new to testing in jest and I was wondering if I could receive some clarity on a matter I am having difficulty understanding.
const getSelectField = () =>
<SelectField
name={name}
id={id}
aria-label="test"
value={value}
options={options} />;
describe('Select Field', () => {
it('Renders SelectField', () => {
const selectField = render(getSelectField());
expect(selectField).toMatchSnapshot();
});
it('Renders select field option', () => {
render(getSelectField());
expect(screen.findByRole('combobox'));
});
I want to essentially be able to test the combobox(or select statement) and test the statements within but I really am just struggling to understand why I'm getting the errors I'm getting when it comes to the linting stage.
29:5 error Expect must have a corresponding matcher call jest/valid-expect
29:19 error promise returned from `findByRole` query must be handled testing-library/await-async-query
✖ 2 problems (2 errors, 0 warnings)
You need to make a matcher call after the last expect.
it('Renders select field option', () => {
render(getSelectField());
const comboBox = screen.findByRole('combobox');
expect(comboBox).toBeInDocument();
});
The screen.findByRole return a promise with a HTMLElement. which you dont handle.
Maybe try
screen.getByRole('combobox');