2017-04-24 58 views
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; 
      }; 

     }); 

服务代码:

"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); 
    }); 

}); 

回答

0

在你测试你有拼写错误:

result.toEqualt(); 

删除 'T'。

+0

rrd,它的错误.....它再次失败 – Mukesh

相关问题