Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

164
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda