Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore .catch promise in code coverage with istanbul?

I'm using BluebirdJS promise library and I have .catch that I can't mock that is why I can't cover it with my code coverage using istanbul.

.then(() => ....)
/* istanbul ignore next */ -> Does not work
.catch((err) => err) /// I want to ignore this

Is this possible with istanbul library?

This is the full code, my test can't reach the .catch because it's always passing and I can't seem to another way to force mongoose to throw an error

 const { payload } = request

 const group = new LocationGroups(payload)

 group.save()
   .then(reply)
   .catch((error) => reply(boomify(error)))
like image 869
kdlcruz Avatar asked Oct 13 '25 10:10

kdlcruz


2 Answers

try {

} catch (err) /* istanbul ignore next */ {

}
like image 139
Suhail AKhtar Avatar answered Oct 15 '25 03:10

Suhail AKhtar


In your case

group.save()
   .then(reply)
   .catch(  /* istanbul ignore next */(error) => reply(boomify(error)))

Alternatively, you can wrap your catch in another block

 try {
    stuff()
  } catch (err) {
    /* istanbul ignore next */ {
      console.error(err)
      throw err
    }
  }

like image 41
Hithesh k Avatar answered Oct 15 '25 02:10

Hithesh k