在 Angular JS 业力测试中管理依赖关系
Managing dependencies in Angular JS karma grunt testing
我的控制器:
/**
* @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);
我的模块 :
(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);
我的单元测试用例规格:
(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);
在 Ctrl 中,我只是指'$scope'
和'$log'
——
ctrl = $controller('caDashboardController',
{
'$scope': scopeMock,
'$log': logMock
//'configService': configServiceMock
//'caCommonService' :caCommonServiceMock,
//'caConsumptionChartService': caConsumptionChartServiceMock
});
我得到很少的错误;
Error: [$injector:unpr] Unknown provider: configServiceProvider <- configService <- caCommonService
Error: Declaration Location
Error: Expected undefined to be defined.
请帮助我如何配置它。如您所见,我没有在我的控制器中使用任何东西。它几乎是空的,但我仍然收到此错误。我没有参考configService
但错误与此有关。
(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.
}
相关文章:
- 在 Angular JS 业力测试中管理依赖关系
- 在 webpack 中管理 jQuery 插件依赖关系
- MeteorJS中的依赖管理
- ES6模块导入和依赖关系管理
- 如何管理不同的 Angular 模块依赖关系
- 如何管理原始对象之间的数据依赖关系
- 使用Sencha's app.json来管理Javascript加载顺序和依赖关系
- 管理web组件的依赖关系;JS、CSS/SASS和模板文件
- 管理承诺依赖项
- 在每个页面中使 bower 依赖项管理可选
- 如何在状态管理器视图控制器中传递已解析的依赖项
- AngularJS:依赖关系管理
- 如何管理Javascript库中的依赖关系
- 如何管理Angular js依赖关系和模块化
- 依赖Javascript的管理和打包
- 我应该如何管理AngularJS中的依赖关系
- 是否应将Bower管理的依赖项签入存储库
- jasmine-maven插件:管理依赖关系和单独的规范执行
- 为什么Angular JS中的依赖项注入比手工管理依赖项更好
- 如何在不使用组件时使用浏览器化管理依赖项