2

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 1

5

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)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.