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
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 Respostas
Responde à pergunta

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 Relatório
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