I am trying to unit test this line of javascript with Jasmine framework :
$scope.validerStyleTag = function() {
$scope.currentTag = JSON.parse($scope.tagList);
for (var i = $scope.listTags.length - 1; i >= 0; i--) {
if ($scope.listTags[i]._id === $scope.currentTag._id) {
$scope.tagID = $scope.listTags[i]._id;
$scope.listTags[i].disabled = true;
break;
}
}
// var textestyler = angular.element(document.querySelector('#style-affected-add'))[0].outerHTML;
// var debut = textestyler.substring(textestyler.indexOf('<p'), textestyler.indexOf('>') + 1);
// var texteFinal = debut + '</p>';
var mytext = '<p data-font="' + $scope.policeList + '" data-size="' + $scope.tailleList + '" data-lineheight="' + $scope.interligneList + '" data-weight="' + $scope.weightList + '" data-coloration="' + $scope.colorList + '"> </p>';
$scope.tagStyles.push({
id_tag: $scope.currentTag._id,
style: mytext,
label: $scope.currentTag.libelle,
police: $scope.policeList,
taille: $scope.tailleList,
interligne: $scope.interligneList,
styleValue: $scope.weightList,
coloration: $scope.colorList,
});
angular.element($('.shown-text-add').text($('.shown-text-add').text()));
angular.element($('#style-affected-add').removeAttr('style'));
$scope.colorationCount = 0;
$scope.tagList = null;
$scope.policeList = null;
$scope.tailleList = null;
$scope.interligneList = null;
$scope.weightList = null;
$scope.colorList = null;
};
the problem of testing is in the first line :
$scope.currentTag = JSON.parse($scope.tagList);
when i begin to write my unit test like this and call my function :
it('ProfilesCtrl:validerStyleTag should set validerStyleTag ', inject(function() {
expect($scope.validerStyleTag).toBeDefined();
$scope.validerStyleTag();
}));
karma is giving me an unexpected error : TypeError: Attempted to assign to readonly property at workFn (/home/app/bower_components/angular-mocks/angular-mocks.js:2107)
ideas or feedbacks are more than welcome !!