Skip to content

Commit ef80908

Browse files
test(stateEvents): Add delays to superseded transition tests.
1 parent 193ac2e commit ef80908

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

test/stateEventsSpec.js

+19-8
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ describe('UI-Router v0.2.x $state events', function () {
3636
C = {},
3737
D = { params: { x: {}, y: {} } },
3838
DD = { parent: D, params: { z: {} } },
39-
E = { params: { i: {} } };
39+
E = { params: { i: {} } },
40+
F = { resolve: {
41+
delay: function($timeout) { return $timeout(50); }
42+
}};
4043

4144
beforeEach(module(function ($stateProvider, $provide) {
4245
angular.forEach([ A, B, C, D, DD ], function (state) {
@@ -51,7 +54,8 @@ describe('UI-Router v0.2.x $state events', function () {
5154
.state('C', C)
5255
.state('D', D)
5356
.state('DD', DD)
54-
.state('E', E);
57+
.state('E', E)
58+
.state('F', F);
5559
}));
5660

5761
beforeEach(inject(function ($rootScope, _$injector_) {
@@ -299,31 +303,38 @@ describe('UI-Router v0.2.x $state events', function () {
299303
}));
300304

301305

302-
it('aborts pending transitions even when going back to the current state', inject(function ($state, $q) {
306+
it('aborts pending transitions even when going back to the current state', inject(function ($state, $q, $timeout) {
303307
initStateTo(A);
304308
logEvents = true;
305309
$state.defaultErrorHandler(function() {});
306310

307-
var superseded = $state.transitionTo(B, {});
311+
var superseded = $state.transitionTo(F, {});
312+
$q.flush();
313+
expect($state.current).toBe(A);
314+
308315
$state.transitionTo(A, {});
309316
$q.flush();
317+
$timeout.flush();
310318
expect($state.current).toBe(A);
311319
expect(resolvedError(superseded)).toBeTruthy();
312-
expect(log).toBe('$stateChangeStart(B,A);');
320+
expect(log).toBe('$stateChangeStart(F,A);');
313321
}));
314322

315-
it('aborts pending transitions (last call wins)', inject(function ($state, $q) {
323+
it('aborts pending transitions (last call wins)', inject(function ($state, $q, $timeout) {
316324
initStateTo(A);
317325
logEvents = true;
318326
$state.defaultErrorHandler(function() {});
319327

320-
var superseded = $state.transitionTo(B, {});
328+
var superseded = $state.transitionTo(F, {});
329+
$q.flush();
330+
321331
$state.transitionTo(C, {});
322332
$q.flush();
333+
$timeout.flush();
323334
expect($state.current).toBe(C);
324335
expect(resolvedError(superseded)).toBeTruthy();
325336
expect(log).toBe(
326-
'$stateChangeStart(B,A);' +
337+
'$stateChangeStart(F,A);' +
327338
'$stateChangeStart(C,A);' +
328339
'$stateChangeSuccess(C,A);');
329340
}));

0 commit comments

Comments
 (0)