Organizational Research By

Surprising Reserch Topic

Experts Most Trusted Topic


karma unexpected request get no more request expected


karma unexpected request get no more request expected  using -'javascript,angularjs,unit-testing,karma-runner,karma-jasmine'

THE SITUATION:

I am testing two different http calls in my AngularJs app.

There is a strange behavior. If i test each one separately, with the other temporary commented out (in the controller and in the test) each one works fine and the test passes.

But if I run karma when there are both the tests, they fail, giving the following error message:

Unexpected request: GET https://MY_DOMAIN_2.com/list_project
No more request expected


THE CONTROLLER:

.controller('TestController', function($scope, $http, $timeout) {

    $scope.getLanguageList = function()
    {
        $http.get('http://MY_DOMAIN_1.org/languageList').then(function(resp)
        {
            $scope.language_list = resp.data;
        },
        function(err)
        {
            $scope.language_list = [];
        })
    }

    $scope.language_list = [];
    $scope.getLanguageList();


    $scope.get_project_list = function()
    {
        $http.get('https://MY_DOMAIN_2.com/projectList').then(function(resp)
        {
            $scope.project_list = resp.data;
        },
        function(err)
        {
            $scope.project_list = [];
        })
    }

    $scope.project_list = [];
    $scope.get_project_list();

})


THE TEST:

describe('Http requests tests', function() {

beforeEach(module('meetinghand_app.controllers'));

var $controller;
var $httpBackend;
var $scope;
var $timeout;


describe('Lists test', function()
{

    beforeEach(angular.mock.http.init);
    afterEach(angular.mock.http.reset);

    beforeEach(inject(function(_$controller_, _$httpBackend_)
    {
        $controller = _$controller_;
        $scope = {};
        $httpBackend = _$httpBackend_;

    }));


    it('should load default language list (with real http request)', function (done)
    {
        $httpBackend.whenGET('http://MY_DOMAIN_1.org/languageList').passThrough();

        var TestController = $controller('TestController', { $scope: $scope });

        setTimeout(function()
        {
            expect($scope.language_list).not.toEqual([]);
            done();
        }, 1000);

    });


    it('should load default project list (with real http request)', function (done)
    {
        $httpBackend.whenGET('httpS://MY_DOMAIN_2.org/projectList').passThrough();

        var TestController = $controller('TestController', { $scope: $scope });

        setTimeout(function()
        {
            expect($scope.project_list).not.toEqual([]);
            done();
        }, 1000);

    });

});

});


THE QUESTION:

Why i am getting that error message?
The code should be fine since separately they are working fine. Am I missing something?

Thank you!
    

asked Oct 19, 2015 by gauravg.gwl
0 votes
56 views



Related Hot Questions



Walkin Jobs Opening



Government Jobs Opening


...