我正在写茉莉测试用例以下角度函数获得测试案例失败的消息“预期间谍[目标对象]已被称为”。
$scope.displayTagModelPopup = function() {
var dialogOptions = {
templateUrl: 'views/mytags.html',
controller: 'TagsCtrl',
size: 'lg',
resolve: {
tagsAvailable: function() {
return $scope.availableTags;
}
}
};
ModalDialogFactory.showDialog(dialogOptions).then(function(result) {
$scope.selectedFields = [];
$scope.selectedFieldIds = [];
angular.forEach(result, function(tag) {
$scope.selectedFields.push(tag);
$scope.selectedFieldIds.push(tag.objectId);
});
});
};
我的茉莉花测试用例
it('should call displayTagModelPopup', function() {
var dialogOptions = {
templateUrl: 'views/mytags.html',
controller: 'TagsCtrl',
size: 'lg',
tagsAvailable: [{
objectId: "c647abc7-f651-4df6-880d-cf9fb69cdcb0",
dataFieldName: "author",
shortNamePath: "$.author",
templates: ["HaM sheet"]
}]
};
var spy = jasmine.createSpy(modalDialogFactory, 'showDialog').and.callFake(function(data) {
$scope.tags = [{
objectId: "c647abc7-f651-4df6-880d-cf9fb69cdcb0",
dataFieldName: "author",
shortNamePath: "$.author",
templates: ["HaM sheet"]
}];
return $scope.tags;
});
$scope.displayTagModelPopup();
$scope.$digest();
expect(spy).toHaveBeenCalled();
});
并且提示以下错误:“预期间谍[目标对象]已被称为错误:预期间谍[目标对象]已被称为”。
是什么在我的测试案例的问题?我失去了什么?
提前致谢!!!
编辑:改变了我的茉莉花测试用例像下面让不同的消息“”未定义“不是(评估‘ModalDialogFactory.showDialog(dialogOptions)。然后’)”功能
尝试是否ModelDialogFactory被定义或没有,但ModalDialogFactory.showDialog方法成功定义。 获得测试情况下,只有调用该方法时失败“$ scope.displayTagModelPopup();”
it('should call displayTagModelPopup', function() {
spyOn(ModalDialogFactory, 'showDialog').and.callFake(function() {
$scope.tags = [{
objectId: "c647abc7-f651-4df6-880d-cf9fb69cdcb0",
dataFieldName: "author",
shortNamePath: "$.author",
templates: ["HaM sheet"]
}];
return $scope.tags;
});
var dialogOptions = {
templateUrl: 'views/mytags.html',
controller: 'TagsCtrl',
size: 'lg',
tagsAvailable: [{
objectId: "c647abc7-f651-4df6-880d-cf9fb69cdcb0",
dataFieldName: "author",
shortNamePath: "$.author",
templates: ["HaM sheet"]
}]
};
//expect(ModalDialogFactory).toBeDefined();
//expect(ModalDialogFactory.showDialog).toBeDefined();
$scope.displayTagModelPopup();
$scope.$digest();
});