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

191
Views
How do I do api jest testing with BDD style in NodeJs Jest?

The test below is passing. However there'd be no coverage. Apparently the promise does not resolve which is always in pending state. What I did is to break the Promise chain and put the pieces in two different functions to make it look like BDD style.

How do I get that covering my code. Any help would be much appreciated?

NodeJs 14.17.3 ts-jest 27.4.1 Jest 27.4.1.

const request = require('supertest')

let res:Promise<any>
let a:string
let b:string

it('should return ....', async () => {
   given('', '')
   when()
   then()
}

async function given(a:string, b:string) {
   // assignments go here 
}

async function when() {
   cons runPro = async (): Promise<any> => {
       return new Promise((resolve, reject) => {
             request(baseurl).get('theurl').then((value:any) => {
                  resolve(value.body)
             }).catch(error => {
                  reject(err)
              })
         }).catch(error => {
            // 
         }
     }
      res = runPro()
}

async function then() {
     res.then(value => {
        expect(value).toEqual("")
    }
}
about 4 years ago · Juan Pablo Isaza
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!