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

257
Visualizações
How to write a test for checking whether value for input field is been set in Jest for a React application?

I have created a login form and am using Jest to test it. I am having trouble using simulate with change to check whether the value has been set or not. Code has been provided for reference.

Login.js (The input field for username)

<Form onSubmit={handleSubmit}>
                    <Form.Group className="form-elements" controlId="nameForm">
                        <Form.Label className="form-label">Username:</Form.Label>
                        <Form.Control className="form-control" type="text" name="username" value={name} required placeholder="Enter name" onChange={(e)=>setName(e.target.value)}/>
                    </Form.Group>

Login.test.js - Test case for checking username

describe('Test case for testing login',() =>{
  let wrapper;
  test('username check',()=>
  {
    wrapper = shallow(<Login/>);
    const ele = wrapper.find("FormControl[type='text']")
    ele.simulate("change", {target: { name:'username',value: 'UserFirst'}});
    console.log(...ele);
    expect(ele).toHaveProperty('value', 'UserFirst')
    
  })
})

The result for console.log(...ele) is:

It shows the value is not set

What could be the solution for this?

about 4 years ago · Juan Pablo Isaza
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