用karma测试登录失败,得到了意外请求的错误

时间:2016-12-12 13:59:04

标签: angularjs unit-testing karma-runner karma-jasmine httpbackend

我在使用业力测试我的auth端点时出错了

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

})

我以为我已经冲洗了()?为什么它会调用我的partial / dashboard.html?我输了。

0 个答案:

没有答案