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

176
Visualizações
Jest data type assestions returning incorrect types

I am using the JestJS library to unit test my nodeJS application. When testing for returning data types, some tests are failing saying that the received data type is something other then what is expected, however the returned data type is incorrect. For example, I have a date string that is being received as an object, but it is in fact a string.

  Received has value: [Error: expect(received).toBe(expected) // Object.is equality·
    Expected: "string"
    Received: "object"]

      82 |     expect(typeof response.data.getPublicDisinfectionByProductStage2[0].details[0].nextSampleDateRange).toBe("string");

Response object being evaluated:

 {
        "systemId": 1289,
        "frequency": "QT",   
        "details": [
          {
            "sampleId": 19842,
            "nextSampleDateRange": "04/01/2022 - 06/30/2022"
          }
]
}

Then with a similar object the test fails with an error:


    expect(received).toMatch(expected)

    Matcher error: received value must be a string

    Received has type:  object
    Received has value: [Error: expect(received).toBe(expected) // Object.is equality·
    Expected: "number"
    Received: "object"]

      107 |     expect(typeof response.data.getPublicOtherDistributionMonitoringPbcu.nextSampleDateRange).toBe("string");
      108 |   } catch (e) {
    > 109 |     expect(e).toMatch("error");
          |               ^
      110 |   }
      111 | });

Where the object being evaluated looks like this:

{
  "data": {
    "getPublicOtherDistributionMonitoringPbcu": {
      "systemId": 1289,
      "lastSampleDate": "2018-09-27 00:00:00",
      "nextSampleDateRange": "06/01/2022 - 09/30/2022"
    }
  }
}

Can someone help me understand what's happening here?

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