Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

156
Views
Jest test functions on select statements in React JS

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)
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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');
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!