0

In my test I am getting this error:

Error: No pending request to flush !
at Function.$httpBackend.flush (/home/arpho/Projects/neo4Scrum/app/bower_components/angular-mocks/angular-mocks.js:1482:34)
at null.<anonymous> (/home/arpho/Projects/neo4Scrum/test/spec/controllers/customer.js:95:18)

This is my code:

'use strict';

describe('Controller: CustomerCtrl', function () {

  // load the controller's module
  beforeEach(module('neo4ScrumApp'));

  var MainCtrl,
    scope,
    $httpBackend;

  // Initialize the controller and a mock scope
  beforeEach(inject(function (_$httpBackend_, $controller, $rootScope) {
    $httpBackend = _$httpBackend_;
    $httpBackend.expectGET('/api/customer/:25618')
      .respond({columns:['r','c','o'],
                data:[
                    {data:{ name: 'Giuseppe', surname: 'D\'Amico', note: 'it\'s me' },id: '25618'},
                    {data:{use:'residenza'},type: 'LIVES_IN'},// relazione indirizzo
                    {data: // item 
                             { }
                    },

                    {data:{ name: 'Giuseppe', surname: 'D\'Amico', note: 'it\'s me' },id: '25618'},
                    {data:{use:'domicilio'},type: 'LIVES_IN'},
                    {data: 
                             { c
                             },
                    },
                    {
                        data: { company: 'H3G', use: 'principale' },
                        type: 'ANSWERS_TO'
                    },
                    {
                        data: { 
                            number: lllll,
                            note: 'intestato a Marco' 
                        },
                     },
                    {data:{ name: 'Giuseppe', surname: 'D\'Amico', note: 'it\'s me' },
                     id: '25618'
                    },
                    {
                        data: { use: 'extra' },
                        type: 'RECEIVES'
                    },
                    {
                        data: { mail: 'mail',
                                use: 'extra' 
                              }
                    },
                    {data:{ name: 'Giuseppe', surname: 'D\'Amico', note: 'it\'s me' },
                     id: '25618'
                    },
                    {
                        data: { use: 'principal' },
                        type: 'RECEIVES'
                    },
                    {
                        data: {
                            mail: 'mail',
                            use: 'principal' 
                        }
                    },
               ]});
      scope = $rootScope.$new();
      MainCtrl = $controller('CustomerCtrl', {
      $scope: scope
    });

  }));

  it('should attach a list of customers with one only item', function () {
    //expect(scope.awesomeThings).toBeUndefined();
    console.log('end test');
    $httpBackend.flush();
    console.log(scope.customers);
    expect(scope.customers.length).toBe(1);
  });
});

I saw other people having my same issue, but I could not solve it my MainCtrl:

'use strict';

angular.module('neo4ScrumApp').controller('MainCtrl', function ($scope, $http) {
  http.get('/api/awesomeThings').success(function(aw){$scope.awesomeThings = aw;})
});

my CustomersCtrl:

'use strict';
angular.module('neo4ScrumApp').controller('CustomerCtrl',['$scope','$http','$routeParams', function($scope,$http,$routeParams) {
    var customerId = $routeParams.customerId; // rimuovo :
    if (typeof customerId != 'undefined') {
        console.log("cerco customer "+customerId);
        $http.get('/api/customer/:'+customerId).success(function(customer) {
            $scope.customer = customer.data[0].data;
            $scope.customer.id = customer.id;
            $scope.action = 'update';
        })
    }
    else 
        $scope.action = 'save';
}])
Uyghur Lives Matter
  • 18,820
  • 42
  • 108
  • 144
arpho
  • 1,576
  • 10
  • 37
  • 57
  • Has the GET request been sent? If yes, by whom, where? – glepretre Feb 10 '14 at 10:52
  • thanks, but why this one: http://pastebin.com/CFfEnKPG is working on a different project? – arpho Feb 10 '14 at 17:08
  • Because it's a different project ;) I think that your controller in the second different project send a GET request on startup (when it's instantiated) but this one doesn't. Could you edit your question and copy your controller code (this one) please? – glepretre Feb 10 '14 at 17:16
  • Possible duplicate of [AngularJS+Jasmine: $httpBackend not working as expected](https://stackoverflow.com/questions/21577718/angularjsjasmine-httpbackend-not-working-as-expected) – Paul Sweatte Jul 11 '17 at 00:36

0 Answers0