【问题标题】:Angular 1.2.10 upgrade kills $httpBackend testsAngular 1.2.10 升级杀死了 $httpBackend 测试
【发布时间】:2014-02-03 19:56:26
【问题描述】:

我刚刚从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 运行良好。有什么想法吗?

【问题讨论】:

    标签: ajax angularjs unit-testing qunit httpbackend


    【解决方案1】:

    由于 1.2.x 已将 ngRoute 移动到单独的文件,您必须在测试配置文件中的 angular.js 之后包含它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-12-02
      • 2020-08-25
      • 1970-01-01
      • 2023-04-02
      • 1970-01-01
      • 1970-01-01
      • 2011-10-30
      相关资源
      最近更新 更多