Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

256
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda