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

366
Views
Jest is throwing Error: expect(received).toThrow()

I have class Person constructor(state, uid). State can only have two values "active" and "inactive". this is how setState function looks like

setState(value) {

    if (value === "active" || "inactive") {
      this._state = value
    } else {
      throw new Error("error")
    }
  }

and Jest is throwing error

Error: expect(received).toThrow()

Received function did not throw

this is the line where error occurs

expect(() =>  p1.setState("bla")).toThrow();

How can I rewrite setState function, so that Jest registers the error.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You made an error in the if statement expression. This is how it should be:

if (value === 'active' || value === 'inactive') {

In your code, the right side of the or operator is a string constant, which will always evaluate to true.

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!