The controller is not a function, has not been defined in jasmine tests with angular (route - $ stateProvider)


i am using angle theme with Angular for my project and i am doing unit testing on this using jasmine framework. But when i run the test cases, it gives error of "Argument 'controller' is not a function, got undefined". here is my test.js file....

var $controller;
    $controller = _$controller_;
it('Check Working Or Not', function() {
    var $scope = {};
    var controller = $controller('registrationController', { $scope: $scope });
    $scope.password = 'passwordlength';


Error -

Error: [ng:areq] Argument 'registrationController' is not a function, got undefined

No i am using karma to run jasmine.

I am defining my module here

var App = angular.module('appTesting', ['ngRoute', 'ngAnimate', 'ngStorage', 'ngCookies', 'pascalprecht.translate', 'ui.bootstrap', 'ui.router', 'oc.lazyLoad', 'cfp.loadingBar', 'ngSanitize', 'ngResource'])
      .run(["$rootScope", "$state", "$stateParams",  '$window', '$templateCache', function ($rootScope, $state, $stateParams, $window, $templateCache, $location) {
          // Set reference to access them from any scope
          $rootScope.$state = $state;
          $rootScope.$stateParams = $stateParams;
          $rootScope.$storage = $window.localStorage;

App.config(['$stateProvider','$urlRouterProvider', '$controllerProvider', '$compileProvider', '$filterProvider', '$provide', '$ocLazyLoadProvider', 'APP_REQUIRES', 'RouteHelpersProvider',
function ($stateProvider, $urlRouterProvider, $controllerProvider, $compileProvider, $filterProvider, $provide, $ocLazyLoadProvider, appRequires, helper) {

 'use strict';
App.controller = $controllerProvider.register;
App.directive  = $compileProvider.directive;
 App.filter     = $filterProvider.register;

App.factory    = $provide.factory;

App.service    = $provide.service;
App.constant   = $provide.constant;
 App.value      = $provide.value;
.state('app.registrationState', {
    url: '/registration',
    title: 'Ragistration Page',
    templateUrl: helper.basepath('registrationPage.html'),
    resolve: helper.resolveFor('registrationController','angularFileUpload')
.controller('NullController', function() {});
App.constant('APP_REQUIRES', {
  'registrationController' :['app/js/registrationcontroller.js'],


Can the controller be found?

  • Do you have a controller named registrationController?
  • Is it in a module named appTesting?

You should have the following code somewhere in your app:

angular.module("appTesting").controller("registrationController", ...);


If you are using Karma-jasmine:

  • Did you include the file where you define the controller (registration-controller.js) in your karma.conf.js?


module.exports = function(config) {config.set({
  files : [


If you're not using Karma to run Jasmine, I'm assuming you're using the Jasmine test runner (HTML file). In that case:

  • Did you include the controller in the HTML file?

You need to include the controller's script:

  <script type="text/javascript" src="src/registration-controller.js"></script>