0

I am new to angular js and trying to unit testing on ngRoute, But Getting this error : TypeError: undefined is not an object (evaluating 'location.path').

Here is my code for Unit testing

describe('Testing angularJS Test Suite', function() {

var location, route, rootScope;
beforeEach(module('myApp'));

beforeEach(inject(
function( _$location_, _$route_, _$rootScope_ ) {
    location = _$location_;
    route = _$route_;
    rootScope = _$rootScope_;
}));


describe('Registration route', function() {
    beforeEach(inject(
        function($httpBackend) {
            $httpBackend.expectGET('views/registration.html')
            .respond(200);
        }));

    it('should load the registration page on successful load of /registration', function() {
        location.path('/registration');
        rootScope.$digest();
        expect(route.current.controller).toBe('RegistrationController')
    });

});
})

Can anyone suggest me, Why I am getting this error. Thanks.

Prasanna Wagh
  • 101
  • 1
  • 5
  • 1
    Possible duplicate of [angularjs route unit testing](http://stackoverflow.com/questions/15990102/angularjs-route-unit-testing) – Matheno Nov 21 '16 at 13:56
  • use $state.go('registration') (assuming 'registration' is your state's name) – rrd Nov 21 '16 at 14:32

0 Answers0