Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.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测试登录失败,收到意外请求错误_Angularjs_Unit Testing_Karma Runner_Karma Jasmine_Httpbackend - Fatal编程技术网

Angularjs 使用karma测试登录失败,收到意外请求错误

Angularjs 使用karma测试登录失败,收到意外请求错误,angularjs,unit-testing,karma-runner,karma-jasmine,httpbackend,Angularjs,Unit Testing,Karma Runner,Karma Jasmine,Httpbackend,我使用karma测试身份验证端点时出错 Error: Unexpected request: GET partials/dashboard.html No more request expected 我的spec.js describe('LogController', function() { var $scope, controller, $location, $window; beforeEach(module('MyApp')); beforeEach(inje

我使用karma测试身份验证端点时出错

Error: Unexpected request: GET partials/dashboard.html
    No more request expected
我的spec.js

describe('LogController', function() {
  var $scope, controller, $location, $window;

  beforeEach(module('MyApp'));

  beforeEach(inject(function($rootScope, $controller, _$location_, _$window_, _$httpBackend_) {
    $scope = $rootScope.$new();
    $window = _$window_;
    $httpBackend = _$httpBackend_;
    $location = _$location_;
    controller = $controller('loginCtrl', {
      $scope: $scope,
      $location: $location,
      $window: $window
    });
  }))

   it('should log in a user and redirect to homepage', function() {

     $httpBackend.whenPOST('/user/login').respond(200);
     $scope.username = 'test';
     $scope.password = '123456';
     $scope.login();

     $httpBackend.flush();
     $scope.$digest();
     expect($location.path()).toBe('/x'); 
   });

})

我以为我已经脸红了?为什么它叫my partial/dashboard.html?我迷路了。

尝试使用
$scope.$apply()而不是
$scope.$digest()@TomePejoski无差别您也可以将代码添加到问题中。@TomePejoski我找到了答案,只是将部分模板列入白名单,但现在我遇到了另一个问题。请尝试使用
$scope.$apply()而不是
$scope.$digest()@TomePejoski没有区别您也可以将代码添加到问题中。@TomePejoski我找到了我的答案,只是将部分模板列入白名单,但现在我遇到了另一个问题。