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("")
}
}