Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 在karma中仅使用http请求测试功能?_Angularjs_Unit Testing_Service_Karma Jasmine - Fatal编程技术网

Angularjs 在karma中仅使用http请求测试功能?

Angularjs 在karma中仅使用http请求测试功能?,angularjs,unit-testing,service,karma-jasmine,Angularjs,Unit Testing,Service,Karma Jasmine,我必须测试AngularJS应用程序,我正在尝试对服务进行单元测试。这些服务具有如下功能: getData: function(){ return $http.get(serviceRoot+'/getData/'+anotherService.id()).then(function(response) { return secondService.validateServerJson(response.data.key); },

我必须测试AngularJS应用程序,我正在尝试对服务进行单元测试。这些服务具有如下功能:

      getData: function(){
      return $http.get(serviceRoot+'/getData/'+anotherService.id()).then(function(response) {
              return secondService.validateServerJson(response.data.key);
      }, function(error) {
        return false;
      })
    },
既然我在模拟http请求,那么为此编写一个测试有什么意义吗?

您可以按如下操作

$httpBackend.expectGET(serviceRoot+'/getData/'+anotherService.id(), function(){}).respond(200,{/*response object*/});
yourserviceinstance.getData();
$httpBackend.flush();
这里是链接

希望这能对你有所帮助