3 angular.module('stateMock', []);
4 angular.module('stateMock').service('$state', function($q) {
5 this.expectedTransitions = [];
7 this.transitionTo = function(stateName) {
8 if (this.expectedTransitions.length > 0) {
9 var expectedState = this.expectedTransitions.shift();
10 if (expectedState !== stateName) {
11 throw Error('Expected transition to state: ' + expectedState + ' but transitioned to ' + stateName);
14 throw Error('No more transitions were expected! Tried to transition to ' + stateName);
16 console.log('Mock transition to: ' + stateName);
17 var deferred = $q.defer();
18 var promise = deferred.promise;
23 this.go = this.transitionTo;
25 this.expectTransitionTo = function(stateName) {
26 this.expectedTransitions.push(stateName);
29 this.ensureAllTransitionsHappened = function() {
30 if (this.expectedTransitions.length > 0) {
31 throw Error('Not all transitions happened!');