Angularjs 使用karma测试登录失败,收到意外请求错误
我使用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
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我找到了我的答案,只是将部分模板列入白名单,但现在我遇到了另一个问题。