describe('Controller:insightSettingsController', function() {
'use strict';
var insightSettingsCtrl;
var settingsService;
var UtilsService;
var scope;
var updateMethodDeferred;
var httpBackend;
var deferred;
var q;
var spy;
beforeEach(module('ui.router',proname.components.insightSettings.module.name));
beforeEach(function() {
var mockUtilsService = {};
module(function(_$provide_) {
_$provide_.value('UtilsService', mockUtilsService);
});
inject(function($q) {
deferred = $q.defer();
mockUtilsService.getConfigurations = function() {};
spyOn(mockUtilsService, 'getConfigurations')
.and.returnValue(deferred.promise);
});
});
beforeEach(inject(function(
_$controller_, _$httpBackend_, _$rootScope_, _settingsService_,
_UtilsService_, _$q_) {
scope = _$rootScope_.$new();
spy = jasmine.createSpy();
settingsService = _settingsService_;
UtilsService = _UtilsService_;
httpBackend = _$httpBackend_;
insightSettingsCtrl = function() {
return _$controller_(
dbmcm.components.settings.insightSettingsController,
{$scope: scope, UtilsService: UtilsService});
};
}));
describe(
'Check Existing Function , parameters, Initialization of function',
function() {
it('should call UtilsService.getConfigurations() once',
function() {
insightSettingsCtrl();
deferred.resolve();
scope.$digest();
expect(UtilsService.getConfigurations).toHaveBeenCalled();
});
});
});
の「service.method」こんにちは、私は、私の別のmodule.Unfortunatelyための角度のテストケースを書いて、私のテストケース破綻上記の私のモジュール、エラーdebug.jsとするのが最良を取得しています: 44 Uncaught Type Error:未定義ののプロパティ 'get Configurations'を読み取ることができません。私は、コントローラの初期化時にgetConfigurations機能を発射、私は関数が実際の実装を発射せず、呼び出されている場合にはジャスミンのスパイが唯一のチェックだと思うキャッチされない例外TypeError:プロパティを読み取ることができません
constructor: function(UtilsService) {
UtilsService.getConfigurations().then(function(response) {
this.utilsConfig_ = response;
}.bind(this));
}
下記をご覧くださいしています。だからgetConfigurations()はエラーをスローします。このため はIその後
it('should call UtilsService.getConfigurations() once',
function() {
spyOn(UtilsService, 'getConfigurations').and.callThrough();
insightSettingsCtrl();
deferred.resolve();
scope.$digest();
expect(UtilsService.getConfigurations).toHaveBeenCalled();
});
});
私のテストケースで.and.callThroughを()を適用し、私はdebug.jsとするのが最良取得しています:私を修正してくださいすでに
時に見張られてきたgetConfigurations:44不明なエラーをどこで間違っているのか。 ありがとうございます。
をあなたはdebug.jsとするのが最良のLN 44である私達に告げることはできますか? –