0
아래의 서비스 기능을 위해 Jasmine 테스트 케이스를 작성하려고했지만 실패했습니다. 아래 코드를 살펴 보겠습니다. 서비스 "getAllNotificationList"에 두 개의 매개 변수를 적어 둡니다. 중첩 된 배열 및 숫자를 가져 와서 중첩 된 배열 데이터를 병합하고 새로운 데이터를 생성합니다.이 데이터는 테스트 케이스 및 해당 실패를 사용하여 동일한 테스트를 시도하면서 정상적으로 작동합니다.아래 각도 서비스를위한 테스트 케이스 작성 방법
컨트롤러 코드 :
angular.module('mobilityApp')
.service('manageNotifications', function(CommonDatahub, API_ENDPOINT, $window) {
/**
* @ngdoc function
* @name getAllNotificationList
* @method Of mobilityApp.service:getAllNotificationList
* @description
* prepare all notification list
*/
this.getAllNotificationList = function(_arrData, _fmno) {
var masterList = _arrData[0],
isUserList = _arrData[1].length > 0 ? true : false,
userList = _arrData[1].length > 0 ? this.convertArrToObj(_arrData[1]) : false,
allNotificationList = [],
count = 0;
masterList.forEach(function(objVal) {
var obj = {},
listName = objVal['name'];
if(isUserList && userList[listName] !== undefined) {
obj = userList[listName];
obj['elemPos'] = count;
} else {
obj['mobilityEventType'] = objVal;
obj['userPreference'] = true;
obj['fmno'] = _fmno;
obj['elemPos'] = count;
}
count++;
allNotificationList.push(obj);
});
console.log(JSON.stringify(allNotificationList));
return allNotificationList;
};
});
서비스 코드 :
result.toEqualt();
는 't'를 제거 테스트에서
"use strict";
describe("ManageNotification API service test", function() {
var manageNotifications, CommonDatahub;
beforeEach(module("mobilityApp"));
beforeEach(inject(function (_manageNotifications_, _CommonDatahub_) {
manageNotifications = _manageNotifications_;
}));
var _fmno = 84194,
_arrData = [[{
"mobilityEventType": "GENERAL",
"description": "Non Partner transfer created",
"defaultSelected": true,
"name": "NP_TRANSFER_CREATED"
}], [{
"id": 100000,
"mobilityEventType": {
"mobilityEventType": "GENERAL",
"description": "Non Partner transfer created",
"defaultSelected": true,
"name": "NP_TRANSFER_CREATED"
},
"userPreference": false,
"fmno": 84194
}]],
_allListData = [{
"mobilityEventType": {
"mobilityEventType": "GENERAL",
"description": "Non Partner transfer created",
"defaultSelected": true,
"name": "NP_TRANSFER_CREATED"
},
"userPreference": false,
"fmno": 84194,
"elemPos": 0
},
{
"id": 100000,
"mobilityEventType": {
"mobilityEventType": "GENERAL",
"description": "Non Partner transfer created",
"defaultSelected": true,
"name": "NP_TRANSFER_CREATED"
},
"userPreference": false,
"fmno": 84194,
"elemPos": 1
}];
it('should merge master and user list and create new list', function() {
var result = manageNotifications.getAllNotificationList(_arrData, _fmno);
result.toEqual(_allListData);
});
});
rrd, 실수 ... 다시 실패했습니다. – Mukesh