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

262
Vistas
Jest focus() is not a function

Here is my file which have button to read more and this button sets focus on element

Component

 ...
 handleFocusOnText = (): void => {
  setTimeout(() => this.hiddenTextRef?.focus(), 500)
 }
...
rednder()
...
<span ref={(el) => (this.hiddenTextRef = el)} tabIndex={-1} innerHTML={hiddenContent} />

<button
 data-qa="readmore-expander-button"
 onClick={this.handleClick}
 >
 {this.isOpen ? this.labelLess : this.labelMore}
 </button>

handleClick method is also calling handleFocusOnText.

Problem is that i call click on this button in my test file and its throwing TS error that focus from handleFocusOnText is not a function. Can you help me out of this issue?

Test.spec.ts

 ....
// Click "read more" button
page.doc.querySelector('button').click()

await page.waitForChanges()
const spanEl = document.querySelector('[data-qa="test-span"]')

expect(spanEl).not.toBeNull()
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I wonder this is not getting right context - how about changing

onClick={this.handleClick}

to

onClick={() => this.handleClick()}

would that work?

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