Я протестировал свой код javascript с помощью jasmine, но когда я вижу покрытие модульных тестов jenkins, у меня есть некоторые строки, которые не отмечены зеленым (не проверены). Вот почему я задаю свой вопрос:
--> Предполагая, что tagStyle.length = 0
$scope.isTagStylesNotEmpty = function() {
if($scope.tagStyles.length >= 0) /* This line is RED (not covered ) */
{
return true;/* This line is Green OK*/
}
}
--> Мой тест следующий:
it('Unit test isTagStylesNotEmpty()', inject(function($httpBackend) {
expect($scope.isTagStylesNotEmpty).toBeDefined();
$scope.isTagStylesNotEmpty();
expect($scope.tagStyles.length).toBe(0);
}));
Есть идеи по этому поводу?
Второй вопрос такой же, как и первый, но немного сложнее:
У меня есть следующий файл Javascript, который я хочу протестировать с помощью jasmine:
$scope.ajouterProfilTag = function(lastDocId) {
$scope.tagStyles.forEach(function(item) {
/*Not covered from here (by jenkins )--------------------*/
var profilTag = {
tag: item.id_tag,
texte: item.style,
profil: lastDocId,
tagName: item.label,
police: item.police,
taille: item.taille,
interligne: item.interligne ,
styleValue: item.styleValue,
};
$http.post('/ajouterProfilTag', profilTag)
.success(function(data) {
$scope.profilTagFlag = data; /* unit tests */
$scope.afficherProfils();
$scope.profilTag = {};
$scope.tagStyles.length = 0;
$scope.tagStyles = [];
/*Until here --------------------*/
});
});
$scope.tagList = {};
$scope.policeList = {};
$scope.tailleList = {};
$scope.interligneList = {};
$scope.weightList = {};
};
мой модульный тест выглядит примерно так:
var profil = {
_id: "52d8f928548367ee2d000006",
photo: "./files/profilImage.jpg",
descriptif: "descriptif3",
niveauScolaire: "CM2",
type: "Dyslexie N2",
nom: "Nom3"
};
var profilTag = {
_id: "52d8f928548367ee2d000006",
tag: "tag",
texte: "texte",
profil: "profil",
tagName: "tagName",
police: "Arial",
taille: "eight",
interligne: "fourteen",
styleValue: "Bold"
}
beforeEach(inject(function($controller, $rootScope, $httpBackend) {
$scope = $rootScope.$new();
controller = $controller('ProfilesCtrl', {
$scope: $scope
});
$httpBackend.whenPOST('/ajouterProfilTag').respond(profilTag);
}));
it('ProfilesCtrl:ajouterProfilTag should set ajouterProfilTag function', inject(function($httpBackend) {
expect($scope.ajouterProfilTag).toBeDefined();
$scope.ajouterProfilTag(profil._id);
$httpBackend.flush();
expect($scope.profilTagFlag).toEqual(profilTag);
}));
Любые идеи о том, как мне провести модульное тестирование моего второго метода (AjouterProfilTag) ?? заранее спасибо
$scope = $rootScope.$new(); controller = $controller('ProfilesCtrl', { $scope: $scope });
- person badaboum   schedule 20.01.2014