Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

244
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda