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

243
Vistas
How to check data in Jest

I'm using the Jest package to test my Node application server-side. I need to check the value and type of the result from my request to the server.

  1. Is it possible to expect the result to be an object like this?

  2. And how to check string[] ?

The result is from the request:

{
  "definitions": [
    "One who subsists on charity; a dependent. South."
  ],
  "pos": "n.",
  "word": "ELEEMOSYNARY"
}

My check to be:

definitions - string[]
pos - "n."
word - string

My code is :


** expect(typeof (res.body.definitions)).toEqual('string'); ???? **

expect(res.body.pos).toEqual('n.');
expect(typeof (res.body.word)).toEqual('string');
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can check the length of definitions or check if Array.isArray() is true, and also the string at position zero like this:

// Either this for the array check
expect(res.body.definitions.length).toEqual(1);
// Or this for the array check
expect(Array.isArray(res.body.definitions)).toStrictEqual(true);

// And this for the string check of the array
expect(res.body.definitions[0]).toEqual("One who subsists on charity; a dependent. South.");

I'm assuming you have this api request/response mocked so you can rely on the value of definitions[0] to check the string.

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