|
| 1 | +describe('state', function () { |
| 2 | + |
| 3 | + beforeEach(module('ui.state')); |
| 4 | + |
| 5 | + describe('(transitions and related promises)', function () { |
| 6 | + var A = { data: {} }; |
| 7 | + |
| 8 | + beforeEach(module(function ($stateProvider) { |
| 9 | + $stateProvider.state('A', A) |
| 10 | + })); |
| 11 | + |
| 12 | + it('.current is always defined', inject(function ($state) { |
| 13 | + expect($state.current).toBeDefined(); |
| 14 | + })); |
| 15 | + |
| 16 | + it('.$current is always defined', inject(function ($state) { |
| 17 | + expect($state.$current).toBeDefined(); |
| 18 | + })); |
| 19 | + |
| 20 | + it('.$current wraps the raw state object', inject(function ($state) { |
| 21 | + resolvedValue($state.transitionTo(A, {})); |
| 22 | + expect($state.$current.data).toBe(A.data); // 'data' is reserved for app use |
| 23 | + })); |
| 24 | + |
| 25 | + it('.transitionTo() returns a promise for the target state', inject(function ($state) { |
| 26 | + var trans = $state.transitionTo(A, {}); |
| 27 | + expect(resolvedValue(trans)).toBe(A); |
| 28 | + })); |
| 29 | + |
| 30 | + it('.current updates asynchronously as the transitionTo() promise is resolved', inject(function ($state) { |
| 31 | + var trans = $state.transitionTo(A, {}); |
| 32 | + expect($state.current).not.toBe(A); |
| 33 | + resolvedValue(trans); |
| 34 | + expect($state.current).toBe(A); |
| 35 | + })); |
| 36 | + |
| 37 | + it('.$transition is always the current or last transition', inject(function ($state) { |
| 38 | + expect($state.$transition).toBeDefined(); |
| 39 | + expect(resolvedValue($state.$transition)).toBe($state.current); |
| 40 | + var trans = $state.transitionTo(A, {}); |
| 41 | + expect($state.$transition).toBeDefined(); |
| 42 | + expect($state.$transition).toBe(trans); |
| 43 | + resolvedValue(trans); |
| 44 | + expect($state.$transition).toBe(trans); |
| 45 | + })); |
| 46 | + |
| 47 | + it('.transition is null when no transition is taking place', inject(function ($state) { |
| 48 | + expect($state.transition).toBeNull(); |
| 49 | + resolvedValue($state.transitionTo(A, {})); |
| 50 | + expect($state.transition).toBeNull(); |
| 51 | + })); |
| 52 | + }); |
| 53 | +}); |
0 commit comments