lundi 26 février 2018

Unit testing capture failure not shown in istanbul code coverage

I'm trying to capture an error with my tests. I have istanbul showing that a current path is not covered by my tests. I think I have it covered but I'm curious why it's not showing in my coverage report.

This is the bit of code i'm testing, It says that my error if route is never covered.

pool.getConnection((err, connection) => {
if (err) {
  console.log(err.message)
  return false
}
else{
   console.log('Connected!!');
 }
});

and here is the test I have for that

it("Should fail to provide a test database connection" , function(done){
let pool  = mysql.createPool({
  connectionLimit : 200,
  host     : '***',
  user     : 'correctuser',
  password : 'WRONGPASSWORD',
  database : 'db'
});
pool.getConnection(function(err, connection) {
  if(err){
    console.log(err.message);
    done();
  }
});
})

Aucun commentaire:

Enregistrer un commentaire