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

368
Vistas
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 Respuestas
Responde la pregunta

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 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