Ich habe folgende Controller ViewMeetingCtrl.jsSpy auf einem Service-Methodenaufruf mit Jasmin Spies
(function() {
'use strict';
angular.module('MyApp').controller('ViewMeetingCtrl', ViewMeetingCtrl);
ViewMeetingCtrl.$inject = ['$scope', '$state', '$http', '$translate', 'notificationService', 'meetingService', '$modal', 'meeting', 'attachmentService'];
function ViewMeetingCtrl($scope, $state, $http, $translate, notificationService, meetingService, $modal, meeting, attachmentService) {
$scope.meeting = meeting;
$scope.cancelMeeting = cancelMeeting;
function cancelMeeting(meetingId, companyId) {
meetingService.sendCancelNotices(companyId, meetingId)
.success(function() {
$state.go('company.view');
});
}
}
})();
konnte ich succussfully die spyOn aufrufen für cancelMeeting() aber nicht mit der Berufung von sendCancelNotices Methode. Was ich tun möchte ist, ich möchte testen, ob immer cancelMeeting() ruft, ruft es sendCancelNotices() Methode. Ich weiß, dass ich mit createSpy Methode gehen sollte, um dies zu tun. Aber ich bin nicht sicher, wie es geht.
Unten ist der Testfall ViewMeetingCtrlSpec.js
describe('ViewMeetingCtrl CreateSpy --> Spying --> cancelMeeting', function() {
var $rootScope, scope, $controller , $q ;
var sendCancelNoticesSpy = jasmine.createSpy('sendCancelNoticesSpy');
beforeEach(angular.mock.module('MyApp'));
beforeEach(inject(function ($rootScope, $controller) {
scope = $rootScope.$new();
createController = function() {
return $controller('ViewMeetingCtrl', {
$scope: scope,
meeting : {}
});
};
var controller = new createController();
}));
it("tracks that the cancelMeeting spy was called", function() {
//some assertion
});
});
eigentlich brauchen Sie nur die spyOn Methode wie spyOn verwenden (Service, 'Methode') http: //jasmine.github .io/2.0/einführung.html das wird die ursprüngliche Methode nach der Durchführung der Spion-Operationen –