Я только что обновился с 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. Любые идеи?