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

202
Vistas
Obtener valor de referencia del elemento HTML

¿Cómo puedo obtener la referencia de un elemento HTML en la biblioteca de pruebas? Tengo esto hasta ahora:

 it('element container ref should be null if prop noSwipe is passed', () => { const onCloseMock = jest.fn() render(<Wrapper onClose={onCloseMock} noSwipe />) const container = screen.getByTestId('container') expect(container.ref).toBeNull() // Want to implement this line })
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Tal vez algo así es lo que estás buscando:

 import React, {createRef} from 'react'; import * as TestUtils from 'react-dom/test-utils'; import CheckboxWithLabel from '../CheckboxWithLabel'; it('CheckboxWithLabel changes the text after click', () => { const checkboxLabelRef = createRef(); const checkboxInputRef = createRef(); // Render a checkbox with label in the document TestUtils.renderIntoDocument( <CheckboxWithLabel labelRef={checkboxLabelRef} inputRef={checkboxInputRef} labelOn="On" labelOff="Off" />, ); const labelNode = checkboxLabelRef.current; const inputNode = checkboxInputRef.current; // Verify that it's Off by default expect(labelNode.textContent).toEqual('Off'); // Simulate a click and verify that it is now On TestUtils.Simulate.change(inputNode); expect(labelNode.textContent).toEqual('On'); });

Viene del ejemplo de reacción de broma, puedes leerlo aquí

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