lucassp
lucassp

Reputation: 4167

When migrating from Angular 1.5 to 1.6 routing is ran inside unit tests

I've migrated my app to Angular 1.6 and suddenly unit test aren't working anymore. After investigating a little I found out that routing is enabled when running unit tests.

The code that I have added extra to the $routeProvider is this one:

$routeProvider.whenAuthenticated = function (path, route) {
    route.resolve = route.resolve || {};
    
    angular.extend(route.resolve, {
        isAuthenticated: ['Auth', function (auth) {
             return auth.authenticate();
        }]
    });

    return $routeProvider.when(path, route);
};

and

$routeProvider
    .whenAuthenticated('/', {
        redirectTo: '/dashboards'
    });

In Angular 1.5 the auth.authenticate() is never hit, while in Angular 1.6 the app tries to navigate to one of my routes and then auth.authenticate() is hit, and the url changes to "/dashboards". Does anybody have an idea about what changed in 1.6? Do I need to do something extra to disable routing while testing?

Upvotes: 1

Views: 239

Answers (1)

lucassp
lucassp

Reputation: 4167

In 1.6 the way the $route service and its dependencies are instantiated has changed, and will - by default - be instantiated early on.

Migrating from Previous Versions

Upvotes: 1

Related Questions