Aşağıdaki kontrolörünü var ViewMeetingCtrl.jsSpy
(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');
});
}
}
})();
Ben succussfully cancelMeeting() için değil ait arama ile spyOn çağırmak başardı SendCancelNotices yöntemi. Ne yapmak istediğim, cancelMeeting() çağrıldığında, sendCancelNotices() yöntemini çağırdığını test etmek istiyorum. Bunu yapmak için createSpy yöntemiyle gitmem gerektiğini biliyorum. Ama nasıl yapacağımı bilmiyorum.
Aşağıda ben hizmetlerden döndürülen HTTP sözlerin güvenerek durdurmak için teşvik edecek test durumu
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
});
});
aslında sadece spyOn spyOn gibi yöntemi kullanmak gerekir (hizmet, 'yöntem') http: //jasmine.github .io/2.0/inst.html , casusluk ile ilgili işlemleri gerçekleştirdikten sonra orijinal yöntemi invoque –