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

126
Vistas
Testing React-form-hook for Select in Enzyme and jest with Controller API

I want to test my below Select and simulate on change event. but currently the onchange is not working. On selecting certain option from the dropwdown, I wan to show a Input field but I am unable to simulate onchange event. Everything is working fine in the JSX file. but not getting simulated properly in the Test File.

    const accType = watch('accountType');
        <Controller
                control={control}
                name="accountType"
                label="Account Type"
                rules={{ required: true }}
                render={({ onChange, ref }) => (
                  <Select
                    onChange={(e) => onChange(e.target.value)}
                    className={styles.w100}
                    defaultValue={bankAccountTypes[0]}
                  >
                    {bankAccountTypes.map((type) => (
                      <MenuItem key={type} value={type}>
                        {type}
                      </MenuItem>
                    ))}
                  </Select>
                )}
              />

{
          accType === 'NRO Savings Account' ? (
            <Grid item={true} xs={12} className={`${styles.fieldItem}`}>
              <TextField
                InputLabelProps={{ shrink: true }}
                className={styles.w100}
                type="text"
                name="country"
                required={true}
                label="Country"
                inputRef={register({ required: true })}
              />
            </Grid>
          ) : null
        }

Below is my Test file

// Country Field should be hidden
let country = component.find({ name: 'country' });
expect(country).toHaveLength(0);

// Simulate Account type field to display Country Dropdown
await act(async () => {
  accountType.simulate('change', { value: 'NRO Savings Account' });
});

// Country field should be present now
country = component.find({ name: 'country' });
expect(country).toHaveLength(1);

//Expected length: 1
//Received length: 0

I am using Jest and Enzyme here in React

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