mercredi 4 février 2015

Very challenging directive - looking for guidance on how to unit test

I just realized that none of the tests I have written for my directive are working in a way that actually tests anything so I am rewriting them. Problem is I cant figure out a way to test the link functions.


If anyone has a suggestion I would really really appreciate it.


Thanks for looking



angular.module('pb.webSites.directives')
.directive('pbOrganizationImagePicker', [ function () {

return {
restrict: "E",
template: '<img data-ng-src="{{ imageSource }}" width="{{width}}" height="{{height}}" alt="Image Picker" class="img-rounded" />',
scope: {
fileId: '=pbFileId',
defaultSrc: '@pbDefaultSrc',
width: '@pbWidth',
height: '@pbHeight'
},
controller: 'pbOrganizationImagePickerController',

link: function (scope, element, attrs) {
scope.$watch('defaultSrc', function (value) {
if (value !== undefined) {
scope.imageSource = value;
}
});

element.on('click', function () {
scope.pickImage().then(function (image) {
scope.imageSource = image.storageUrl;
scope.fileId = image.fileId;
}, function () {
console.log('Modal dismissed at: ' + new Date());
});
});
}
};
}]);

Aucun commentaire:

Enregistrer un commentaire