I setup a test for a route based on this answer. I now want to check if things injected to the route's controller are setup correctly. From the state object, I can only get the controller's constructor function. I am wondering how can I access the actual instance?
1 Answer
This is probably way too roundabout to be the official solution, but it seems like it could work. If you use controller-as syntax in your state, i.e. "SomeController as ctrl", then it gets added to the $scope object with the given name. Afterwards, you can find this at:
$state.$current.locals['@viewname'].$scope.ctrl
...where '@viewname' would be the name of your view, and 'ctrl' is your controller alias.
There probably should be a simpler way to do this. It'd be a pretty handy feature for writing tests that span multiple states (without resorting to things like Protractor/Selenium)