我刚从Angular.js 1.1.3
升级到1.2.10
,我的$httpBackend
测试开始失败。我使用QUnit 1.12.0
作为测试框架。
我的测试中有以下设置。
(function () {
var fittingDataServiceMock,
injector,
ctrl,
$scope,
$httpBackend;
module("Fitting Controller Test", {
setup: function() {
injector = angular.injector(['ngMock', 'ng','fittingApp']);
$scope = injector.get('$rootScope').$new();
$httpBackend = injector.get('$httpBackend');
fittingDataServiceMock = injector.get('fittingDataService');
//expects a post on controller creation
$httpBackend.expectPOST('/app_dev.php/client_api/command').respond("hello");
ctrl = injector.get('$controller')(DoubleVariableController, { $scope: $scope, fittingDataService: fittingDataServiceMock });
$httpBackend.flush();
},
teardown: function() {
}
test ("DoubleVariableController Simple Test", function() {
$httpBackend.expectPOST('/app_dev.php/client_api/command').respond(200, {data: "Hello"});
// make an AJAX Posts
$httpBackend.flush();
}
});
在这种情况下,我得到两个失败的测试
第一次错误:
Setup failed on DoubleVariableController Simple Test: No pending request to flush!
at Error (native)
at Function.$httpBackend.flush (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.1.1/angular-mocks.js:1148:34)
第二次错误:
Died on test #2 ... No pending request to flush !
Error: No pending request to flush !
at Error (native)
at Function.$httpBackend.flush (http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.1.1/angular-mocks.js:1148:34)
我不知道为什么所有的突然发布请求都没有通过。使用Angular 1.1.3,测试工作正常。有什么想法吗?
答案 0 :(得分:-1)
由于1.2.x已将ngRoute移动到单独的文件,您必须在测试配置文件中的angular.js之后包含它。