【发布时间】:2014-06-11 21:59:36
【问题描述】:
我需要一些帮助,我在实际阅读整个文件方面取得了一些进展,但是,我遇到了一个相当大的障碍(对我来说这很不错,我是新手)。我正在尝试模拟控制器的大部分内容,当我读取文件大约一半时遇到了问题,我不知道如何克服它。我将在下面包含尽可能多的代码。
LocationController.js
angular
.module('TDE')
.controller('LocationController', ['$rootScope', '$scope', '$location', '$window', '$document', 'LocationService', 'HeaderFooterService', 'SearchService', 'TranslationService', 'MTDE_CONFIG', 'LocationPartnerAssignmentService', 'ExperimentService', function ($rootScope, $scope, $location, $window, $document, $LocationService, $HeaderFooterService, $SearchService, $TranslationService, $MTDE_CONFIG, $LocationPartnerAssignmentService, $ExperimentService) {
//passes over this code
$scope.init = function () {
// load dropdown for crop list
// load dropdown for business partner list
//load dropdown for experimenttype
//load dropdown for IrrigationType
//load dropdown for previousCrop
var locationId = $SearchService.GetLocationId();
$scope.LocationId=locationId;
var experimentId = $SearchService.GetExperimentId();
var experimentPartnerAssignmentId = $SearchService.GetExperimentPartnerAssignmentId();
//load nitrogen value
$ExperimentService.GetCrop(onSuccessCropCode,cropId);
// get location detail from database
if (locationId === "00000000-0000-0000-0000-000000000000") {
// Load the Unassigned Location here
$scope.IsAssinged = false;
}
else {
$LocationService.Detail(onSuccessDetail, locationId);
}
// get growing year list
$scope.GrowingYearList = $LocationService.GrowingYearList();
}
$scope.init(); //I NEED TO BE MOCKED SOMEHOW
Helper.js
ddescribe("Phases of Testing: The Journey", function () {
describe("Phase I: Test that Jasmine runs", function () {
it("should test Jasmine is up", function () {
expect(true).toBe(true);
});
});
describe("Phase II: Try something", function () {
var DBMock, SyncMock, baseMock, configMock, TransMock, loginMock, locMock, headerMock,
searchMock, LPAMock, expMock, mockScope, $location, $scope, ctrl, initMock;
beforeEach(function () {
angular.mock.module('TDE');
inject(function (_$location_, _$rootScope_, _$controller_) {
$location = _$location_;
$scope = _$rootScope_.$new();
ctrl = _$controller_('LocationController', {
'$scope': $scope
});
});
});
it("should be able to grab something", function () {
expect(true).toBe(true);
expect($scope).toBeDefined();
expect($scope.PlantingDateNull()).toBeTruthy();
});
});
});
编辑: 现在问题归结为在最初定义后模拟 $scope.init() 函数调用。我在任何地方都找不到很好的帮助来源。
【问题讨论】:
标签: javascript angularjs unit-testing jasmine