मैं एक तत्व के निर्देश है कि इसके link
समारोह में एक सेवा कॉल बना रहा हूं:AngularJS निर्देश लिंक समारोह चमेली की परीक्षा में नहीं बुलाया
app.directive('depositList', ['depositService', function (depositService) {
return {
templateUrl: 'depositList.html',
restrict: 'E',
scope: {
status: '@status',
title: '@title'
},
link: function (scope) {
scope.depositsInfo = depositService.getDeposits({
status: scope.status
});
}
};
}]);
सेवा अब के लिए मामूली बात है:
app.factory('depositService', function(){
return {
getDeposits: function(criteria){
return 'you searched for : ' + criteria.status;
}
};
});
मैं मैं एक परीक्षण लिखने की कोशिश कर रहा हूं जो सुनिश्चित करता है कि depositService.getDeposits()
सही स्थिति मान के साथ कहा जाता है। क्योंकि बार === 0. इस कोड को ब्राउज़र में ठीक चलाता
describe('Testing the directive', function() {
beforeEach(module('plunker'));
it('should query for pending deposits', inject(function ($rootScope, $compile, $httpBackend, depositService) {
spyOn(depositService, 'getDeposits').and.callFake(function(criteria){
return 'blah';
});
$httpBackend.when('GET', 'depositList.html')
.respond('<div></div>');
var elementString = '<deposit-list status="pending" title="blah"></deposit-list>';
var element = angular.element(elementString);
var scope = $rootScope.$new();
$compile(element)(scope);
scope.$digest();
var times = depositService.getDeposits.calls.all().length;
expect(times).toBe(1);
}));
});
परीक्षण विफल रहता है, लेकिन परीक्षा में link
समारोह और सेवा कभी नहीं कहा जा लगते हैं। कोई विचार?
plunker: http://plnkr.co/edit/69jK8c
मैं मुझे बहुत ही बड़ी जानकारी के इस टुकड़े को खोजने के लिए ले लिया। धन्यवाद! :) – Tudmotu
इससे मुझे बहुत मदद मिली, धन्यवाद! –