AngularJS, route resolve, location change, unit tests, karma-jasmine
<p>In angular i've written a route resolve on all actions, to check wether you are logged in or not</p>

<pre><code>$routeProvider.when('/home', {
    resolve: {
        Authenticated: function($location, AuthAuthenticator, AuthIdentity) {
            return new Promise(function(resolve, reject) {
                AuthAuthenticator.init().then(
                    function( success ) {
                        if (!AuthAuthenticator.isAuthenticated() ) {
                            $location.path("/login");
                            resolve( true );
                        }
                        resolve( false );
                    },
                    function( error ) {
                        reject( error );
                    }
                );
            });
        }
    }
});
</code></pre>

<p>If you are not logged in we redirect you towards the login page. Now i want to test this in our karma-jasmine unit test. But if i write the test, location.path doesn't change.</p>

<pre><code>describe('LoginController', function() {
    beforeEach(module('dcApp'));

    beforeEach(function() {
        var _authenticated = false;

        AuthAuthenticatorMock = {
            isAuthenticated: function() {
                return _authenticated
            },

            setAuthenticated: function( authenticated ) {
                _authenticated = authenticated;
            },
        };

        module( function( $provide ) {
            $provide.value('AuthAuthenticator', AuthAuthenticatorMock);
        });
    });

    var $controller;

    beforeEach(inject(function( _$route_, _$location_, _$controller_, _AuthAuthenticator_ ){
        // The injector unwraps the underscores (_) from around the parameter names when matching
        $route = _$route_;
        $location = _$location_;
        $controller = _$controller_;
        AuthAuthenticator = _AuthAuthenticator_;
    }));

    describe('Controller activation', function() {
        it ('redirects to login if user is not yet logged in', function() {
            AuthAuthenticator.setAuthenticated( false );
            var $scope = {};
            var controller = $controller('HomeController', { $scope: $scope });
            expect( $location.path() ).toBe('/login');
        });
    });

});
</code></pre>

<p>But the result is:</p>

<pre><code>PhantomJS 2.1.1 (Linux 0.0.0) HomeController Controller activation redirects to login if user is not yet logged in FAILED
Expected '' to be '/login'.
</code></pre>

<p>Now i've seen some documentation on spy, but i don't get how to check for this location change.</p>