1+ import { IPromise } from 'angular' ;
12import * as angular from 'angular' ;
2- import './util/matchers' ;
33import './util/testUtilsNg1' ;
44
55declare var inject ;
66import Spy = jasmine . Spy ;
7- import './util/matchers' ;
8- import { resolvedValue , resolvedError , caught } from './util/testUtilsNg1' ;
7+ import { resolvedValue , resolvedError , caught , testablePromise } from './util/testUtilsNg1' ;
98import { ResolveContext , StateObject , PathNode , omit , pick , inherit , forEach } from '@uirouter/core' ;
109import { UIRouter , Resolvable , services , StateDeclaration } from '@uirouter/core' ;
1110import '../src/legacy/resolveService' ;
@@ -214,6 +213,10 @@ function makePath(names: string[]): PathNode[] {
214213 return names . map ( ( name ) => new PathNode ( statesMap [ name ] ) ) ;
215214}
216215
216+ function isResolved ( promise : IPromise < any > ) {
217+ return ! ! testablePromise ( promise ) . $$resolved ;
218+ }
219+
217220describe ( 'Resolvables system:' , function ( ) {
218221 beforeEach ( inject ( function ( $transitions , $injector ) {
219222 emptyPath = [ ] ;
@@ -290,7 +293,7 @@ describe('$resolve', function () {
290293 const fun : Spy = jasmine . createSpy ( 'fun' ) ;
291294 fun . and . returnValue ( 42 ) ;
292295 const r = $r . resolve ( { fun : [ '$resolve' , fun ] } ) ;
293- expect ( r ) . not . toBeResolved ( ) ;
296+ expect ( isResolved ( r ) ) . toBe ( false ) ;
294297 tick ( ) ;
295298 expect ( resolvedValue ( r ) ) . toEqual ( { fun : 42 } ) ;
296299 expect ( fun ) . toHaveBeenCalled ( ) ;
@@ -304,7 +307,7 @@ describe('$resolve', function () {
304307 const fun = jasmine . createSpy ( 'fun' ) . and . returnValue ( d . promise ) ;
305308 const r = $r . resolve ( { fun : [ '$resolve' , fun ] } ) ;
306309 tick ( ) ;
307- expect ( r ) . not . toBeResolved ( ) ;
310+ expect ( isResolved ( r ) ) . toBe ( false ) ;
308311 d . resolve ( 'async' ) ;
309312 tick ( ) ;
310313 expect ( resolvedValue ( r ) ) . toEqual ( { fun : 'async' } ) ;
@@ -333,19 +336,19 @@ describe('$resolve', function () {
333336
334337 const r = $r . resolve ( { a : [ 'b' , 'c' , a ] , b : [ 'c' , b ] , c : [ c ] } ) ;
335338 tick ( ) ;
336- expect ( r ) . not . toBeResolved ( ) ;
339+ expect ( isResolved ( r ) ) . toBe ( false ) ;
337340 expect ( a ) . not . toHaveBeenCalled ( ) ;
338341 expect ( b ) . not . toHaveBeenCalled ( ) ;
339342 expect ( c ) . toHaveBeenCalled ( ) ;
340343 cd . resolve ( 'cc' ) ;
341344 tick ( ) ;
342- expect ( r ) . not . toBeResolved ( ) ;
345+ expect ( isResolved ( r ) ) . toBe ( false ) ;
343346 expect ( a ) . not . toHaveBeenCalled ( ) ;
344347 expect ( b ) . toHaveBeenCalled ( ) ;
345348 expect ( b . calls . mostRecent ( ) . args ) . toEqual ( [ 'cc' ] ) ;
346349 bd . resolve ( 'bb' ) ;
347350 tick ( ) ;
348- expect ( r ) . not . toBeResolved ( ) ;
351+ expect ( isResolved ( r ) ) . toBe ( false ) ;
349352 expect ( a ) . toHaveBeenCalled ( ) ;
350353 expect ( a . calls . mostRecent ( ) . args ) . toEqual ( [ 'bb' , 'cc' ] ) ;
351354 ad . resolve ( 'aa' ) ;
@@ -418,7 +421,7 @@ describe('$resolve', function () {
418421 r
419422 ) ;
420423 tick ( ) ;
421- expect ( r ) . toBeResolved ( ) ;
424+ expect ( isResolved ( r ) ) . toBe ( true ) ;
422425 expect ( resolvedValue ( s ) ) . toEqual ( { fun : true , games : true } ) ;
423426 } ) ;
424427
@@ -561,8 +564,8 @@ describe('$resolve', function () {
561564 const s = $r . resolve ( { b : [ b ] } , { } , r ) ;
562565 bd . resolve ( 'bbb' ) ;
563566 tick ( ) ;
564- expect ( r ) . not . toBeResolved ( ) ;
565- expect ( s ) . not . toBeResolved ( ) ;
567+ expect ( isResolved ( r ) ) . toBe ( false ) ;
568+ expect ( isResolved ( s ) ) . toBe ( false ) ;
566569 cd . resolve ( 'ccc' ) ;
567570 tick ( ) ;
568571 expect ( resolvedValue ( r ) ) . toEqual ( { c : 'ccc' } ) ;
@@ -571,9 +574,9 @@ describe('$resolve', function () {
571574
572575 it ( 'rejects missing dependencies but does not fail synchronously' , function ( ) {
573576 const r = $r . resolve ( { fun : function ( invalid ) { } } ) ;
574- expect ( r ) . not . toBeResolved ( ) ;
577+ expect ( isResolved ( r ) ) . toBe ( false ) ;
575578 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) ;
577580 } ) ;
578581
579582 it ( 'propagates exceptions thrown by the functions as a rejection' , function ( ) {
@@ -582,7 +585,7 @@ describe('$resolve', function () {
582585 throw 'i want cake' ;
583586 } ,
584587 } ) ;
585- expect ( r ) . not . toBeResolved ( ) ;
588+ expect ( isResolved ( r ) ) . toBe ( false ) ;
586589 tick ( ) ;
587590 expect ( resolvedError ( r ) ) . toBe ( 'i want cake' ) ;
588591 } ) ;
@@ -614,7 +617,7 @@ describe('$resolve', function () {
614617 } ,
615618 } ) ;
616619 tick ( ) ;
617- expect ( r ) . toBeResolved ( ) ;
620+ expect ( isResolved ( r ) ) . toBe ( true ) ;
618621 const a = jasmine . createSpy ( 'a' ) ;
619622 const s = $r . resolve ( { a : [ a ] } , { } , r ) ;
620623 tick ( ) ;
@@ -707,14 +710,14 @@ describe('Integration: Resolvables system', () => {
707710 $transitions . onStart ( { to : 'J' } , ( $transition$ ) => {
708711 const ctx = new ResolveContext ( $transition$ . treeChanges ( ) . to ) ;
709712 return invokeLater ( function ( _J ) { } , ctx ) . then ( function ( ) {
710- expect ( counts . _J ) . toEqualData ( 1 ) ;
713+ expect ( counts . _J ) . toEqual ( 1 ) ;
711714 return $state . target ( 'K' ) ;
712715 } ) ;
713716 } ) ;
714717 $state . go ( 'J' ) ;
715718 $rootScope . $digest ( ) ;
716719 expect ( $state . current . name ) . toBe ( 'K' ) ;
717- expect ( counts . _J ) . toEqualData ( 1 ) ;
720+ expect ( counts . _J ) . toEqual ( 1 ) ;
718721 } ) ;
719722
720723 // Test for https://github.com/angular-ui/ui-router/issues/3546
0 commit comments