Can't do $httpBackend.passThrough() with unit tests/karma

220 views
Skip to first unread message

Ryan Zec

unread,
Apr 17, 2013, 3:07:42 PM4/17/13
to ang...@googlegroups.com
I am running angular 1.1.4

So I have the following karma configuration file:

    basePath = '../htdocs';

    files = [
        JASMINE,
        JASMINE_ADAPTER,
        //bunch more includes, note I am using angular-mocks
    ];

    autoWatch = false;

    browsers = ['Chrome','Firefox','Safari'];

    singleRun = true;

and here is an example of a unit test file

    describe('Desktop Controller', function(){
        var scope, $controller, controllerOptions, $httpBackend, callback, unitTestMocker;
    
        beforeEach(module('of'));
        beforeEach(module('unitTestMocker'));
    
        beforeEach(inject(function($injector, $rootScope) {
            $httpBackend = $injector.get('$httpBackend');
            callback = jasmine.createSpy();
            scope = $rootScope.$new();
            $controller = $injector.get('$controller');
            unitTestMocker = $injector.get('unitTestMocker');
            controllerOptions = {
                $scope: scope
            };
    
            $httpBackend.when('GET', /\.html$/).passThrough();
        }));
    
        afterEach(function() {
            $httpBackend.verifyNoOutstandingExpectation();
            $httpBackend.verifyNoOutstandingRequest();
        });
    
        it('should have basic elements', function() {
            unitTestMocker.setValidLoadSessionResponse();
            var controller = new $controller('DesktopCtrl', controllerOptions);
            unitTestMocker.flush();
    
            //make sure the session data got loaded
            expect(scope.session.get('user').firstName).toEqual('Good');
            expect(scope.session.get('user').lastName).toEqual('User');
        });
    });

The issue is that I get the error passThrough() is not a method and that would only happen according to the angular source code if $browser does not get set.  I though that running the unit tests like I am (specifying the specific browsers) would get the $browser defined since I though the test were executed in actual browsers.  Should I not have access to passThrough() in unit tests with karma?

Reply all
Reply to author
Forward
0 new messages