jasmine を使用して JavaScript コードをテストしましたが、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);
}));
その点についてのアイデアはありますか?
2 番目の質問は最初の質問と同じですが、少し複雑です。
jasmine で単体テストしたい次の Javascript ファイルがあります。
$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);
}));
2番目のメソッド(AjouterProfilTag)を単体テストする方法についてのアイデアはありますか?? 前もって感謝します