简体   繁体   English

TypeError:无法调用未定义的方法“ get”

[英]TypeError: Cannot call method 'get' of undefined

I am using AngularJs and Protractor for testing api data and trying getting response from the server using restapi and then display that data on console. 我正在使用AngularJs和Protractor测试api数据,并尝试使用restapi从服务器获取响应,然后在控制台上显示该数据。

Bellow is my Code. 波纹管是我的代码。

My Service File: 我的服务档案:

module.exports = {getResponse : function ($http){

    $http.get('http://echo.jsontest.com/title/ipsum/content/blah').
      success(function(data, status, headers, config) {
          console.log(data)
          var jsonData = JSON.stringify(data);
          console.log(jsonData);
          // this callback will be called asynchronously    
          // when the response is available
      }).
      error(function(data, status, headers, config) {
        // called asynchronously if an error occurs
        // or server returns response with an error status.
      });
    }   

};    

Testcase File : 测试用例文件:

 var helper = require('./helper');
 describe('A test suite', function() {  

   it('does something to myService', function() {
        var result = helper.getResponse();  
        console.log(result);    
   }); 
  });

Thanks in advance... 提前致谢...

Did you include $http in your service delcaration? 您是否在服务代理中包括$http

angular.module('app').service('YourService', ['$http', function($http) {

// your code

}]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM