|
1 |
| -import { ResolveContext, StateObject, PathNode, Resolvable, copy } from '../src/index'; |
| 1 | +import { tail } from '../src/common/common'; |
2 | 2 | import { services } from '../src/common/coreservices';
|
3 |
| -import { tree2Array } from './_testUtils'; |
| 3 | +import { copy, CustomAsyncPolicy, PathNode, Resolvable, ResolveContext, StateObject } from '../src/index'; |
4 | 4 | import { UIRouter } from '../src/router';
|
5 |
| - |
6 |
| -import { TestingPlugin } from './_testingPlugin'; |
| 5 | +import { StateRegistry } from '../src/state/stateRegistry'; |
7 | 6 | import { StateService } from '../src/state/stateService';
|
8 | 7 | import { TransitionService } from '../src/transition/transitionService';
|
9 |
| -import { StateRegistry } from '../src/state/stateRegistry'; |
10 |
| -import { tail } from '../src/common/common'; |
| 8 | + |
| 9 | +import { TestingPlugin } from './_testingPlugin'; |
| 10 | +import { tree2Array } from './_testUtils'; |
11 | 11 |
|
12 | 12 | ///////////////////////////////////////////////
|
13 | 13 |
|
@@ -426,6 +426,7 @@ describe('Resolvables system:', function() {
|
426 | 426 | const ctx = new ResolveContext(path);
|
427 | 427 |
|
428 | 428 | let result;
|
| 429 | + |
429 | 430 | function checkCounts() {
|
430 | 431 | expect(result).toBe('JJ2K');
|
431 | 432 | expect(counts['_J']).toBe(1);
|
@@ -561,10 +562,11 @@ describe('Resolvables system:', function() {
|
561 | 562 |
|
562 | 563 | describe('NOWAIT Resolve Policy', () => {
|
563 | 564 | it('should allow a transition to complete before the resolve is settled', async done => {
|
564 |
| - let resolve, |
565 |
| - resolvePromise = new Promise(_resolve => { |
566 |
| - resolve = _resolve; |
567 |
| - }); |
| 565 | + let resolve; |
| 566 | + |
| 567 | + const resolvePromise = new Promise(_resolve => { |
| 568 | + resolve = _resolve; |
| 569 | + }); |
568 | 570 |
|
569 | 571 | $registry.register({
|
570 | 572 | name: 'nowait',
|
@@ -599,10 +601,11 @@ describe('Resolvables system:', function() {
|
599 | 601 | });
|
600 | 602 |
|
601 | 603 | it('should wait for WAIT resolves and not wait for NOWAIT resolves', async done => {
|
602 |
| - let promiseResolveFn, |
603 |
| - resolvePromise = new Promise(resolve => { |
604 |
| - promiseResolveFn = resolve; |
605 |
| - }); |
| 604 | + let promiseResolveFn; |
| 605 | + |
| 606 | + const resolvePromise = new Promise(resolve => { |
| 607 | + promiseResolveFn = resolve; |
| 608 | + }); |
606 | 609 |
|
607 | 610 | $registry.register({
|
608 | 611 | name: 'nowait',
|
@@ -635,4 +638,39 @@ describe('Resolvables system:', function() {
|
635 | 638 | $state.go('nowait');
|
636 | 639 | });
|
637 | 640 | });
|
| 641 | + |
| 642 | + describe('custom Resolve Policy', () => { |
| 643 | + let customResolvePolicy: CustomAsyncPolicy; |
| 644 | + |
| 645 | + it('should wait for the promise to resolve before finishing the transition', async done => { |
| 646 | + let resolve: (value: string) => void; |
| 647 | + |
| 648 | + const resolvePromise: Promise<string> = new Promise(_resolve => { |
| 649 | + resolve = _resolve; |
| 650 | + }); |
| 651 | + |
| 652 | + customResolvePolicy = jasmine.createSpy('customResolvePolicy'); |
| 653 | + |
| 654 | + (customResolvePolicy as jasmine.Spy).and.callFake((data: { useMe: Promise<string> }) => { |
| 655 | + return data.useMe; |
| 656 | + }); |
| 657 | + |
| 658 | + resolve('myAwaitedValue'); |
| 659 | + |
| 660 | + $registry.register({ |
| 661 | + name: 'customPolicy', |
| 662 | + resolve: { |
| 663 | + customWait: () => ({ useMe: resolvePromise }), |
| 664 | + }, |
| 665 | + resolvePolicy: { async: customResolvePolicy }, |
| 666 | + }); |
| 667 | + |
| 668 | + $transitions.onSuccess({}, trans => { |
| 669 | + expect(customResolvePolicy).toHaveBeenCalledWith({ useMe: resolvePromise }); |
| 670 | + expect(trans.injector().get('customWait')).toBe('myAwaitedValue'); |
| 671 | + }); |
| 672 | + |
| 673 | + $state.go('customPolicy').then(done); |
| 674 | + }); |
| 675 | + }); |
638 | 676 | });
|
0 commit comments