Reputation: 5803
My controller :
/**
* @description
* Controller for Comparative Analysis dashboard.
*/
(function (define) {
define([], function () {
/**
* Constructor function.
*
* @param {Object} $scope Object that binds model to view.
* @param {Object} $log object(angular service) to log info,waring and error messages.
*
*/
//var caDashboardController = function ($scope, $log, configService, caCommonService, caConsumptionChartService) {
var caDashboardController = function ($scope, $log) {
}
return ["$scope", "$log", caDashboardController];
});
})(define);
My Module :
(function (define, angular) {
'user strict'
define([
'myAnalytics/comparativeAnalysis/dashboard/controllers/caDashboardController',
], function (caDashboardController) {
var moduleName = "AnalyticsApp.comparativeAnalysis";
angular.module(moduleName, ['ngRoute', 'ngResource', 'kendo.directives'])
.config(['$routeProvider', function config($routeProvider) {
$routeProvider.when('/comparativeAnalysis', {
controller: 'caDashboardController',
templateUrl: 'app/myAnalytics/comparativeAnalysis/dashboard/comparativeAnalysisdashboard.html'
});
}])
.controller("caDashboardController", caDashboardController);
return moduleName;
});
})(define, angular);
My Unit test case Spec :
(function (define) {
'use strict';
define([
'kendo',
'angularRoute',
'angularResource',
'moment',
'myAnalytics/comparativeAnalysis/dashboard/comparativeAnalysisModule'
],
function () {
describe('Test for comparative Analysis Dashboard Controller', function () {
var scopeMock, logMock, ctrl, configServiceMock, caCommonServiceMock, caConsumptionChartServiceMock;
var serviceResponse = null;
var deferredCompareResult;
beforeEach(module('AnalyticsApp.comparativeAnalysis'));
beforeEach(inject(function ($rootScope, $log, caCommonService, caConsumptionChartService) {
scopeMock = $rootScope.$new();
logMock = $log;
//configServiceMock = { comparativeAnalysisUrl: '/COMPARATIVEANALYSISURL/' };
configServiceMock = { csrServiceUrl: '/CSRSERVICEURL/' };//$injector.get('configService');
caCommonServiceMock = caCommonService;
caConsumptionChartServiceMock = caConsumptionChartService;
}));
describe('Successful Server response tests', function () {
beforeEach(inject(function ($controller, $q) {
deferredCompareResult = $q.defer();
deferredCompareResult.resolve(serviceResponse);
//spyOn(caCommonServiceMock, 'getData').and.returnValue(deferredCompareResult.promise);
//spyOn(caConsumptionChartServiceMock, 'getChartData').and.returnValue(deferredCompareResult.promise);
ctrl = $controller('caDashboardController',
{
'$scope': scopeMock,
'$log': logMock
//'configService': configServiceMock
//'caCommonService' :caCommonServiceMock,
//'caConsumptionChartService': caConsumptionChartServiceMock
});
}));
it('$scope should be configured', function () {
expect(ctrl).toBeDefined();
});
it('Consumption Graph Data should be set', inject(function ($rootScope) {
//expect(ctrl).toBeDefined();
//expect(scopeMock.caViewModel.chartData).toBeDefined();
////scopeMock.caViewModel.search('');
//expect(caConsumptionChartServiceMock.getChartData).toHaveBeenCalled();
//$rootScope.$apply();
//expect(scopeMock.caViewModel.chartData).toBe(null);
}));
});
});
});
})(define);
In Ctrl I am just referring '$scope'
and '$log'
--
ctrl = $controller('caDashboardController',
{
'$scope': scopeMock,
'$log': logMock
//'configService': configServiceMock
//'caCommonService' :caCommonServiceMock,
//'caConsumptionChartService': caConsumptionChartServiceMock
});
I am getting few errors ;
Error: [$injector:unpr] Unknown provider: configServiceProvider <- configService <- caCommonService
Error: Declaration Location
Error: Expected undefined to be defined.
Please help me How I can configure this. As you can see I am not using anything in my Controller. Its almost empty, But still I am getting this errors..
I have no reference for configService
But error is related to that.
Upvotes: 0
Views: 102
Reputation: 371
(function (define) {
'use strict';
define([
'kendo',
'angularRoute',
'angularResource',
'myAnalytics/comparativeAnalysis/dashboard/services/caCommomService',
'myAnalytics/comparativeAnalysis/dashboard/services/caConsumptionChartServic',
'myAnalytics/comparativeAnalysis/dashboard/controllers/caDashboardController',
],
function (moment,caCommomService,caConsumptionChartServic,caDashboardController) {
var abcController;
beforeEach(inject(function ($rootScope,$controller, $q, $timeout) {
scope = $rootScope.$new();
q = $q;
timeout = $timeout;
abcController = $controller(caDashboardController, {
$scope: scope,
abcService: caConsumptionChartServic
});
}));
// you are using requirejs dependencies so try to pass direct files and use no to get main module.
}
Upvotes: 1