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

246
Views
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 answers
Answer question

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