1
+ import { IPromise } from 'angular' ;
1
2
import * as angular from 'angular' ;
2
- import './util/matchers' ;
3
3
import './util/testUtilsNg1' ;
4
4
5
5
declare var inject ;
6
6
import Spy = jasmine . Spy ;
7
- import './util/matchers' ;
8
- import { resolvedValue , resolvedError , caught } from './util/testUtilsNg1' ;
7
+ import { resolvedValue , resolvedError , caught , testablePromise } from './util/testUtilsNg1' ;
9
8
import { ResolveContext , StateObject , PathNode , omit , pick , inherit , forEach } from '@uirouter/core' ;
10
9
import { UIRouter , Resolvable , services , StateDeclaration } from '@uirouter/core' ;
11
10
import '../src/legacy/resolveService' ;
@@ -214,6 +213,10 @@ function makePath(names: string[]): PathNode[] {
214
213
return names . map ( ( name ) => new PathNode ( statesMap [ name ] ) ) ;
215
214
}
216
215
216
+ function isResolved ( promise : IPromise < any > ) {
217
+ return ! ! testablePromise ( promise ) . $$resolved ;
218
+ }
219
+
217
220
describe ( 'Resolvables system:' , function ( ) {
218
221
beforeEach ( inject ( function ( $transitions , $injector ) {
219
222
emptyPath = [ ] ;
@@ -290,7 +293,7 @@ describe('$resolve', function () {
290
293
const fun : Spy = jasmine . createSpy ( 'fun' ) ;
291
294
fun . and . returnValue ( 42 ) ;
292
295
const r = $r . resolve ( { fun : [ '$resolve' , fun ] } ) ;
293
- expect ( r ) . not . toBeResolved ( ) ;
296
+ expect ( isResolved ( r ) ) . toBe ( false ) ;
294
297
tick ( ) ;
295
298
expect ( resolvedValue ( r ) ) . toEqual ( { fun : 42 } ) ;
296
299
expect ( fun ) . toHaveBeenCalled ( ) ;
@@ -304,7 +307,7 @@ describe('$resolve', function () {
304
307
const fun = jasmine . createSpy ( 'fun' ) . and . returnValue ( d . promise ) ;
305
308
const r = $r . resolve ( { fun : [ '$resolve' , fun ] } ) ;
306
309
tick ( ) ;
307
- expect ( r ) . not . toBeResolved ( ) ;
310
+ expect ( isResolved ( r ) ) . toBe ( false ) ;
308
311
d . resolve ( 'async' ) ;
309
312
tick ( ) ;
310
313
expect ( resolvedValue ( r ) ) . toEqual ( { fun : 'async' } ) ;
@@ -333,19 +336,19 @@ describe('$resolve', function () {
333
336
334
337
const r = $r . resolve ( { a : [ 'b' , 'c' , a ] , b : [ 'c' , b ] , c : [ c ] } ) ;
335
338
tick ( ) ;
336
- expect ( r ) . not . toBeResolved ( ) ;
339
+ expect ( isResolved ( r ) ) . toBe ( false ) ;
337
340
expect ( a ) . not . toHaveBeenCalled ( ) ;
338
341
expect ( b ) . not . toHaveBeenCalled ( ) ;
339
342
expect ( c ) . toHaveBeenCalled ( ) ;
340
343
cd . resolve ( 'cc' ) ;
341
344
tick ( ) ;
342
- expect ( r ) . not . toBeResolved ( ) ;
345
+ expect ( isResolved ( r ) ) . toBe ( false ) ;
343
346
expect ( a ) . not . toHaveBeenCalled ( ) ;
344
347
expect ( b ) . toHaveBeenCalled ( ) ;
345
348
expect ( b . calls . mostRecent ( ) . args ) . toEqual ( [ 'cc' ] ) ;
346
349
bd . resolve ( 'bb' ) ;
347
350
tick ( ) ;
348
- expect ( r ) . not . toBeResolved ( ) ;
351
+ expect ( isResolved ( r ) ) . toBe ( false ) ;
349
352
expect ( a ) . toHaveBeenCalled ( ) ;
350
353
expect ( a . calls . mostRecent ( ) . args ) . toEqual ( [ 'bb' , 'cc' ] ) ;
351
354
ad . resolve ( 'aa' ) ;
@@ -418,7 +421,7 @@ describe('$resolve', function () {
418
421
r
419
422
) ;
420
423
tick ( ) ;
421
- expect ( r ) . toBeResolved ( ) ;
424
+ expect ( isResolved ( r ) ) . toBe ( true ) ;
422
425
expect ( resolvedValue ( s ) ) . toEqual ( { fun : true , games : true } ) ;
423
426
} ) ;
424
427
@@ -561,8 +564,8 @@ describe('$resolve', function () {
561
564
const s = $r . resolve ( { b : [ b ] } , { } , r ) ;
562
565
bd . resolve ( 'bbb' ) ;
563
566
tick ( ) ;
564
- expect ( r ) . not . toBeResolved ( ) ;
565
- expect ( s ) . not . toBeResolved ( ) ;
567
+ expect ( isResolved ( r ) ) . toBe ( false ) ;
568
+ expect ( isResolved ( s ) ) . toBe ( false ) ;
566
569
cd . resolve ( 'ccc' ) ;
567
570
tick ( ) ;
568
571
expect ( resolvedValue ( r ) ) . toEqual ( { c : 'ccc' } ) ;
@@ -571,9 +574,9 @@ describe('$resolve', function () {
571
574
572
575
it ( 'rejects missing dependencies but does not fail synchronously' , function ( ) {
573
576
const r = $r . resolve ( { fun : function ( invalid ) { } } ) ;
574
- expect ( r ) . not . toBeResolved ( ) ;
577
+ expect ( isResolved ( r ) ) . toBe ( false ) ;
575
578
tick ( ) ;
576
- expect ( resolvedError ( r ) ) . toMatch ( / u n k n o w n p r o v i d e r / i) ;
579
+ expect ( resolvedError ( r ) . toString ( ) ) . toMatch ( / u n k n o w n p r o v i d e r / i) ;
577
580
} ) ;
578
581
579
582
it ( 'propagates exceptions thrown by the functions as a rejection' , function ( ) {
@@ -582,7 +585,7 @@ describe('$resolve', function () {
582
585
throw 'i want cake' ;
583
586
} ,
584
587
} ) ;
585
- expect ( r ) . not . toBeResolved ( ) ;
588
+ expect ( isResolved ( r ) ) . toBe ( false ) ;
586
589
tick ( ) ;
587
590
expect ( resolvedError ( r ) ) . toBe ( 'i want cake' ) ;
588
591
} ) ;
@@ -614,7 +617,7 @@ describe('$resolve', function () {
614
617
} ,
615
618
} ) ;
616
619
tick ( ) ;
617
- expect ( r ) . toBeResolved ( ) ;
620
+ expect ( isResolved ( r ) ) . toBe ( true ) ;
618
621
const a = jasmine . createSpy ( 'a' ) ;
619
622
const s = $r . resolve ( { a : [ a ] } , { } , r ) ;
620
623
tick ( ) ;
@@ -707,14 +710,14 @@ describe('Integration: Resolvables system', () => {
707
710
$transitions . onStart ( { to : 'J' } , ( $transition$ ) => {
708
711
const ctx = new ResolveContext ( $transition$ . treeChanges ( ) . to ) ;
709
712
return invokeLater ( function ( _J ) { } , ctx ) . then ( function ( ) {
710
- expect ( counts . _J ) . toEqualData ( 1 ) ;
713
+ expect ( counts . _J ) . toEqual ( 1 ) ;
711
714
return $state . target ( 'K' ) ;
712
715
} ) ;
713
716
} ) ;
714
717
$state . go ( 'J' ) ;
715
718
$rootScope . $digest ( ) ;
716
719
expect ( $state . current . name ) . toBe ( 'K' ) ;
717
- expect ( counts . _J ) . toEqualData ( 1 ) ;
720
+ expect ( counts . _J ) . toEqual ( 1 ) ;
718
721
} ) ;
719
722
720
723
// Test for https://github.com/angular-ui/ui-router/issues/3546
0 commit comments