当我运行测试用例时,预期未定义为等于Object {{samplpe data}}错误

时间:2017-03-03 09:18:20

标签: angularjs karma-jasmine

我在尝试运行以下测试用例和代码时遇到了一些问题。

Javascript代码:

commonService.dataService = function(url, dataObject) {
  var deferred = $q.defer();
  url =(dataObject.requestUrl)?dataObject.requestUrl:''; //for Static Call only
    $http.get(url, {params: dataObject})
      .success(function(data) {
        deferred.resolve(data);
      })
      .error(function(error) {
        deferred.reject(error);
      });
      return deferred.promise;
};

测试用例:

describe('commonService.dataService ', function() {

            it('Should be common service to make http calls ', function(){

                var dataObject = {
                    dataType: "gridPanel",
                    functionLink: "getcaseItemListGrid",
                    panelName: "caseItemListGrid",
                    requestUrl: "../structure/case-item-list-header.json"
                };

                /* code under test */
                  http.get('http://localhost:9000/structure/case-item-list-header.json')
                    .success(function(data) {
                    console.log("Data: "+data);
                      deferred.resolve(data);
                    }).error(function(data) {
                      console.log("Data: "+data);
                  });
                /* end */

                $httpBackend
                    .expectGET('GET', 'http://localhost:9000/structure/case-item-list-header.json')
                    .respond(200,dataObject);

                /*expect($httpBackend.flush).not.toThrow();*/
                expect(deferred.resolve(data)).toEqual(dataObject);
            });
        });

运行测试用例后,我收到以下错误:

  

预期未定义为等于对象{{samplpe data}}

0 个答案:

没有答案