2

I just upgraded from Angular.js 1.1.3 to 1.2.10 and my $httpBackend tests started failing. Im using QUnit 1.12.0 as a testing framework.

I have the following setup in my tests.

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

In this case, I get two failing tests

First Error:

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)

Second Error:

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)

I don't know why all the sudden, post requests are not going through. The tests worked fine using Angular 1.1.3. Any ideas?

Jordan.J.D
  • 7,999
  • 11
  • 48
  • 78
moesef
  • 4,641
  • 16
  • 51
  • 68

1 Answers1

-1

As 1.2.x has move ngRoute to separate file you have to include it after angular.js in your tests configuration file.