I'm trying to unit test my controller, but it is dependent on some data that originates from when the route gets resolved. I just can't figure out how to test that (or not fail the test because it can't find "locals")
The controller:
myMainModule.controller('theController', function theController($scope, $route) {
    [...]
    $scope.variable = $route.current.locals.data;
    [...]
}
The route configuration:
[...].config(function ($routeProvider, $locationProvider) {
    $routeProvider.when([...], {
        templateUrl: [...],
        controller: 'theController',
        resolve: {
            data: [...]
        }
    }
    [...]
} [...]
                In your unit test, inject a fake $route instead of the real one:
var fakeRoute = {
    current: { 
        locals: {
            data: 'someFakeData'
        }
    }
}
$scontroller('theController', {
    $scope: $scope,
    $route: fakeRoute
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With