Search code examples
angularjsunit-testingcode-coveragekarma-runner

How can I improve Karma test coverage on config files in AngularJS?


I have a file app/routes.coffee

'use strict'

webApp.config [
  '$stateProvider'
  '$urlRouterProvider'
  '$locationProvider'
  ($stateProvider, $urlRouterProvider, $locationProvider) ->

    $urlRouterProvider.otherwise '/'

    $stateProvider
    .state('dashboard', {
      url: '/'
      views:
        appView:
          templateUrl: '/templates/app/dashboard.html'
    })
    .state('repository', {
      url: '/repository/:repo_host/:username/:name'
      views:
        appView:
          templateUrl: '/templates/app/repository.html'
    })
    .state('profile', {
      url: '/profile'
      views:
        appView:
          templateUrl: '/templates/app/profile.html'
    })
    .state('faq', {
      url: '/faq'
      views:
        appView:
          templateUrl: '/templates/app/faq.html'
    })
    ... # lots of other states
    .state('account.users.statistics', {
      url: '/:host/:username'
      views:
        statisticsView:
          templateUrl: '/templates/app/_userStatistics.html'
    })

    $locationProvider.html5Mode true
]

However, my code coverage is pretty poor:

Statements: 55.56% (5 / 9) Branches: 0% (0 / 4) Functions: 50% (1 / 2) Lines: 100% (5 / 5) Ignored: none

What can I do to improve my code coverage?


Solution

  • it('should test routeProvider', function() {
        inject(function($route) {
            expect($route.routes['/faq'].controller).toBe('faqCtrl');
            expect($route.routes['/faq'].templateUrl).toEqual('/templates/app/faq.html');
        });
    });
    

    You can test like this. My code is written in angularjs, so I tested like that only using jasmine framework. Sorry, I don't have knowledge in coffescript,