TwoToc code
[YouAndWeb_TwoToc] / client / components / ui-router / ui-router.mock.js
1 'use strict';
2
3 angular.module('stateMock', []);
4 angular.module('stateMock').service('$state', function($q) {
5     this.expectedTransitions = [];
6
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);
12             }
13         } else {
14             throw Error('No more transitions were expected! Tried to transition to ' + stateName);
15         }
16         console.log('Mock transition to: ' + stateName);
17         var deferred = $q.defer();
18         var promise = deferred.promise;
19         deferred.resolve();
20         return promise;
21     };
22
23     this.go = this.transitionTo;
24
25     this.expectTransitionTo = function(stateName) {
26         this.expectedTransitions.push(stateName);
27     };
28
29     this.ensureAllTransitionsHappened = function() {
30         if (this.expectedTransitions.length > 0) {
31             throw Error('Not all transitions happened!');
32         }
33     };
34 });