所以这是我的$ scope函数。我想通过Jasmine测试一下。
$scope.viewIndividualDetailsByTitle = function(details){
$modal.open({
templateUrl: 'components/content-management/content-assessment/partial/title_detail.html',
controller: 'ContentAssessmentTitleDetailCtrl',
size: 'lg',
backdrop: 'static',
resolve: {
cpPortfolioTitle: function(){
return details;
}
}
});
};
这是我在Jasmine写的。
describe('Ctrl: ContentAssessmentCtrl', function(){
beforeEach(module('cmsApp'));
var ContentAssessmentCtrl, scope, modal, modalInstance, httpBackend, ContentAssessmentService, event, controller;
beforeEach(inject(function($controller, $rootScope, $modal, $httpBackend, _ContentAssessmentService_){
scope = $rootScope.$new();
modal = $modal;
httpBackend = $httpBackend;
ContentAssessmentService = _ContentAssessmentService_;
ContentAssessmentCtrl = $controller('ContentAssessmentCtrl', {
$scope: scope,
ContentAssessmentService: ContentAssessmentService
});
modalServiceMock = {
open: function(options) {
}
};
httpBackend.whenGET('/mcw/api/content_provider_status_mapping/contentProviderStatus/3').respond();
scope.$digest();
}));
it('should test viewIndividualDetailsByTitle', function(){
var details = {
contentProvider:{
name:'Test'
},
title: 'Test',
productionYear: 1,
titleCategory:{
name:'Test'
},
runningTime: 1,
country:{
name:'Test',
code:'Test'
}
};
});
it('should show the modal', function(){
spyOn(modal, 'open');
expect(modal.open).toHaveBeenCalled();
});
});
但是我总是有一个错误“预期的间谍被召唤。我是Jasmine的新人,这是我的第一次,所以请耐心等待。谢谢
答案 0 :(得分:2)
看起来你已经完成了测试的所有样板设置,但是你实际上并没有调用打开模态的函数。在创建间谍的行之后,您可以调用:
$scope.viewIndividualDetailsByTitle();