Angularjs unit test controller dependent on route resolution

I am trying to run a unit test on my controller, but it depends on some data that has occurred since the route resolved. I just can't figure out how to check this (or not miss a test because it cannot find "locals")

Controller:

myMainModule.controller('theController', function theController($scope, $route) { [...] $scope.variable = $route.current.locals.data; [...] } 

Route Configuration:

 [...].config(function ($routeProvider, $locationProvider) { $routeProvider.when([...], { templateUrl: [...], controller: 'theController', resolve: { data: [...] } } [...] } [...] 
+6
source share
1 answer

In your unit test, type fake $ route instead of real:

 var fakeRoute = { current: { locals: { data: 'someFakeData' } } } $scontroller('theController', { $scope: $scope, $route: fakeRoute } 
+4
source

All Articles