Wait for stateChange in test
<p>I have a scope function in my controller with some async functions. After everything is done it changes the state.</p>

<p>controller.js</p>

<pre><code>$scope.test = function () {
    async().then(function () {
        $state.go('somewhere');
    });
};
</code></pre>

<p>I could test it with <code>setTimeout()</code> but thats dirty I think.</p>

<p>How do I wait for the stateChange in my test?</p>

<p><strong>Edit:</strong></p>

<p>I want to write unit tests for the <code>test()</code> function but as it is no promise I need to watch for the state change in the test. But how? It works with <code>setTimeout()</code> but I don't want to use <code>setTimeout()</code> because it just doesn't feel right. Is there something like <code>$scope.$watch</code> for states?</p>

<p>test.js</p>

<pre><code>...

it('test()', function (done) {
    $scope.test();
    setTimeout(function () { // I want this replaced with a listener for state
        expect($scope.someVar).to.be.equal('value');
        expect($state.current.name).to.be.equal('somewhere');
    });
});

...
</code></pre>