Question

I'm writing tests for a simple AngularJS project, and using Istanbul to work out code coverage. I've got a file that has 100% code coverage according to istanbul, but I don't have any test for it:

'use strict';

define(['app'],function(app) {
  app.config(['$routeProvider',function ($routeProvider) {
    $routeProvider
      .when('/', {
      templateUrl: 'views/main.html',
        controller: 'MainController'
      })
      .otherwise({
        redirectTo: '/'
      });
  }]);
});

The stats from Istanbul are:

Statements: 100% (4 / 4)      
Branches: 100% (0 / 0)      
Functions: 100% (2 / 2)      
Lines: 100% (4 / 4)     

and the whole HTML report page is "green" to suggest the code coverage is good.

Why would this be? Is there anything to be done about it? (Is it an issue in Istanbul?)

Was it helpful?

Solution

The code coverage only shows if the JavaScript execution has reached those lines, not if there are any tests specifically assigned to it.

Most likely Angular reads route configuration normally during the execution of tests, so everything in the file is marked as covered.

This is also a good reminder that 100% code coverage doesn't automatically mean 100% feature coverage.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top