Skip to content

Commit 773ff3a

Browse files
test(lazyLoad): Failing test for ui-router/angular#40
1 parent cb653ee commit 773ff3a

File tree

1 file changed

+45
-10
lines changed

1 file changed

+45
-10
lines changed

test/lazyLoadSpec.ts

+45-10
Original file line numberDiff line numberDiff line change
@@ -298,26 +298,31 @@ describe('future state', function () {
298298
});
299299

300300
describe('that resolves to multiple states', () => {
301-
let lazyStateDefA = { name: 'A', url: '/a/:id', params: {id: "default"} };
302-
let lazyStateDefAB = { name: 'A.B', url: '/b' };
303-
let futureStateDef;
301+
let futureA, futureB;
302+
let lazyA = { name: 'A', url: '/a/:id', params: {id: "default"} };
303+
let lazyAB = { name: 'A.B', url: '/b' };
304+
305+
306+
let lazyB = { name: 'B', url: '/b' };
307+
let lazyBA = { name: 'B.A', url: '/A' };
308+
let lazyBB = { name: 'B.B', url: '/B' };
304309

305310
beforeEach(() => {
306-
futureStateDef = {
307-
name: 'A.**', url: '/a',
308-
lazyLoad: () => new Promise(resolve => { resolve({ states: [lazyStateDefA, lazyStateDefAB] }); })
309-
};
310-
$registry.register(futureStateDef)
311+
// Re-create each time because the state is mutated: the lazyLoad function is removed after success
312+
futureA = { name: 'A.**', url: '/a', lazyLoad: () => new Promise(resolve => { resolve({ states: [lazyA, lazyAB] }); }) };
313+
futureB = { name: 'B.**', url: '/b', lazyLoad: () => null, };
314+
315+
$registry.register(futureA)
311316
});
312317

313318
it('should register all returned states and remove the placeholder', (done) => {
314319
expect($state.get().map(x=>x.name)).toEqual(["", "A.**"]);
315-
expect($state.get('A')).toBe(futureStateDef);
320+
expect($state.get('A')).toBe(futureA);
316321
expect($state.get('A').lazyLoad).toBeDefined();
317322

318323
$state.go('A').then(() => {
319324
expect($state.get().map(x=>x.name)).toEqual(["", "A", "A.B"]);
320-
expect($state.get('A')).toBe(lazyStateDefA);
325+
expect($state.get('A')).toBe(lazyA);
321326
expect($state.get('A').lazyLoad).toBeUndefined();
322327
expect($state.current.name).toBe('A');
323328
done();
@@ -341,6 +346,36 @@ describe('future state', function () {
341346
done();
342347
});
343348
});
349+
350+
it('should not care about the order of lazy loaded states (1)', (done) => {
351+
futureB.lazyLoad = () => new Promise(resolve => { resolve({ states: [lazyB, lazyBA, lazyBB] }); });
352+
$registry.register(futureB);
353+
354+
$state.go('B.A').then(() => {
355+
expect($state.current.name).toBe('B.A');
356+
done();
357+
});
358+
});
359+
360+
it('should not care about the order of lazy loaded states (2)', (done) => {
361+
futureB.lazyLoad = () => new Promise(resolve => { resolve({ states: [lazyBA, lazyB, lazyBB] }); });
362+
$registry.register(futureB);
363+
364+
$state.go('B.A').then(() => {
365+
expect($state.current.name).toBe('B.A');
366+
done();
367+
});
368+
});
369+
370+
it('should not care about the order of lazy loaded states (3)', (done) => {
371+
futureB.lazyLoad = () => new Promise(resolve => { resolve({ states: [lazyBB, lazyBA, lazyB] }); });
372+
$registry.register(futureB);
373+
374+
$state.go('B.A').then(() => {
375+
expect($state.current.name).toBe('B.A');
376+
done();
377+
});
378+
});
344379
});
345380

346381
it('should not invoke lazyLoad twice', (done) => {

0 commit comments

Comments
 (0)