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

115
Visualizações
Testing onChange Event with jest.. onChange is not firing/calling even if we pass onChange function through props. any suggestion

the below code is returned from render method. I am sending index value as 0 through props. i am also sending onChange function through props. but onchange function is not calling when i do npm run test.

beneficiary.js

 {props.isEditing ? 

    <Textbox 

       id={`beneficiary-value-${props.index}`}

       onChange={(e) => props.onChange(e)}

       inputType={'number'}

    /> :

    <span className={"percentage"}>{`${props.beneficiary.percentage}%`}</span>

  }

.

test.js:

test('Beneficiaries renders without crashing', () => {

let beneficiary =
{
   "name": "Emma Smith",
   "dob": "",
   "relationship": "",
   "percentage": "",
   "hasChanged": false
};
    const onChange = jest.fn();

    const dom = render(

        <BeneficiaryItem beneficiary={beneficiary} index={0} isEditing={true} onChange={(e) => onChange(e)} />

    );

    const beneficiaryValue = dom.container.querySelector("#beneficiary-value-0");

    fireEvent.change(beneficiaryValue);

})

the above is my test case file.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Change event should be fired as below, it expects new value as an argument:

fireEvent.change(beneficiaryValue, {
  target: { value: "Changed Value" }
});

Please refer to React testing library documentation for more details.

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