Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

260
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!