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

238
Views
Jest test expecting specific error to be thrown

I have a Jest test that is expecting a specific error to be thrown on a function, however even when the error is throw it is not detecting it.

async function resolve(hostname) {
   return dns.resolve(hostname)
      .then(ip => (`address: ${ip}`))
      .catch(err => {
         throw new DnsError
      })
}
test('Resolving records', () => {
   expect(() => { dns.resolve('http://fsdfsvsdv') }).toThrowError(DnsError)
})

I'm a little stuck on why this test isn't passing, when I run it I can see in the console that the specific error is in fact being throw but for some reason Jest is not picking that up.. Am I doing something wrong? Any help would be appreciated.

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