@@ -1383,6 +1383,13 @@ describe('Integration', () => {
13831383 useValue :
13841384 ( c : any , a : ActivatedRouteSnapshot , b : RouterStateSnapshot ) => { return false ; }
13851385 } ,
1386+ {
1387+ provide : 'alwaysFalseAndLogging' ,
1388+ useValue : ( c : any , a : ActivatedRouteSnapshot , b : RouterStateSnapshot ) => {
1389+ log . push ( 'called' ) ;
1390+ return false ;
1391+ }
1392+ } ,
13861393 ]
13871394 } ) ;
13881395 } ) ;
@@ -1532,62 +1539,86 @@ describe('Integration', () => {
15321539 expect ( location . path ( ) ) . toEqual ( '/main/component1' ) ;
15331540 } ) ) ) ;
15341541
1535- } ) ;
1536-
1537- describe ( 'should work when given a class' , ( ) => {
1538- class AlwaysTrue implements CanDeactivate < TeamCmp > {
1539- canDeactivate (
1540- component : TeamCmp , route : ActivatedRouteSnapshot ,
1541- state : RouterStateSnapshot ) : boolean {
1542- return true ;
1543- }
1544- }
1542+ it ( 'should call guards every time when navigating to the same url over and over again' ,
1543+ fakeAsync ( inject ( [ Router , Location ] , ( router : Router , location : Location ) => {
1544+ const fixture = createRoot ( router , RootCmp ) ;
15451545
1546- beforeEach ( ( ) => { TestBed . configureTestingModule ( { providers : [ AlwaysTrue ] } ) ; } ) ;
1546+ router . resetConfig ( [
1547+ { path : 'simple' , component : SimpleCmp , canDeactivate : [ 'alwaysFalseAndLogging' ] } ,
1548+ { path : 'blank' , component : BlankCmp }
15471549
1548- it ( 'works' , fakeAsync ( inject ( [ Router , Location ] , ( router : Router , location : Location ) => {
1549- const fixture = createRoot ( router , RootCmp ) ;
1550+ ] ) ;
15501551
1551- router . resetConfig (
1552- [ { path : 'team/:id' , component : TeamCmp , canDeactivate : [ AlwaysTrue ] } ] ) ;
1552+ router . navigateByUrl ( '/simple' ) ;
1553+ advance ( fixture ) ;
15531554
1554- router . navigateByUrl ( '/team/22 ' ) ;
1555+ router . navigateByUrl ( '/blank ' ) ;
15551556 advance ( fixture ) ;
1556- expect ( location . path ( ) ) . toEqual ( '/team/22' ) ;
1557+ expect ( log ) . toEqual ( [ 'called' ] ) ;
1558+ expect ( location . path ( ) ) . toEqual ( '/simple' ) ;
15571559
1558- router . navigateByUrl ( '/team/33 ' ) ;
1560+ router . navigateByUrl ( '/blank ' ) ;
15591561 advance ( fixture ) ;
1560- expect ( location . path ( ) ) . toEqual ( '/team/33' ) ;
1562+ expect ( log ) . toEqual ( [ 'called' , 'called' ] ) ;
1563+ expect ( location . path ( ) ) . toEqual ( '/simple' ) ;
15611564 } ) ) ) ;
1562- } ) ;
15631565
15641566
1565- describe ( 'should work when returns an observable' , ( ) => {
1566- beforeEach ( ( ) => {
1567- TestBed . configureTestingModule ( {
1568- providers : [ {
1569- provide : 'CanDeactivate' ,
1570- useValue : ( c : TeamCmp , a : ActivatedRouteSnapshot , b : RouterStateSnapshot ) => {
1571- return Observable . create ( ( observer : any ) => { observer . next ( false ) ; } ) ;
1572- }
1573- } ]
1574- } ) ;
1567+ describe ( 'should work when given a class' , ( ) => {
1568+ class AlwaysTrue implements CanDeactivate < TeamCmp > {
1569+ canDeactivate (
1570+ component : TeamCmp , route : ActivatedRouteSnapshot ,
1571+ state : RouterStateSnapshot ) : boolean {
1572+ return true ;
1573+ }
1574+ }
1575+
1576+ beforeEach ( ( ) => { TestBed . configureTestingModule ( { providers : [ AlwaysTrue ] } ) ; } ) ;
1577+
1578+ it ( 'works' , fakeAsync ( inject ( [ Router , Location ] , ( router : Router , location : Location ) => {
1579+ const fixture = createRoot ( router , RootCmp ) ;
1580+
1581+ router . resetConfig (
1582+ [ { path : 'team/:id' , component : TeamCmp , canDeactivate : [ AlwaysTrue ] } ] ) ;
1583+
1584+ router . navigateByUrl ( '/team/22' ) ;
1585+ advance ( fixture ) ;
1586+ expect ( location . path ( ) ) . toEqual ( '/team/22' ) ;
1587+
1588+ router . navigateByUrl ( '/team/33' ) ;
1589+ advance ( fixture ) ;
1590+ expect ( location . path ( ) ) . toEqual ( '/team/33' ) ;
1591+ } ) ) ) ;
15751592 } ) ;
15761593
1577- it ( 'works' , fakeAsync ( inject ( [ Router , Location ] , ( router : Router , location : Location ) => {
1578- const fixture = createRoot ( router , RootCmp ) ;
15791594
1580- router . resetConfig (
1581- [ { path : 'team/:id' , component : TeamCmp , canDeactivate : [ 'CanDeactivate' ] } ] ) ;
1595+ describe ( 'should work when returns an observable' , ( ) => {
1596+ beforeEach ( ( ) => {
1597+ TestBed . configureTestingModule ( {
1598+ providers : [ {
1599+ provide : 'CanDeactivate' ,
1600+ useValue : ( c : TeamCmp , a : ActivatedRouteSnapshot , b : RouterStateSnapshot ) => {
1601+ return Observable . create ( ( observer : any ) => { observer . next ( false ) ; } ) ;
1602+ }
1603+ } ]
1604+ } ) ;
1605+ } ) ;
15821606
1583- router . navigateByUrl ( '/team/22' ) ;
1584- advance ( fixture ) ;
1585- expect ( location . path ( ) ) . toEqual ( '/team/22' ) ;
1607+ it ( 'works' , fakeAsync ( inject ( [ Router , Location ] , ( router : Router , location : Location ) => {
1608+ const fixture = createRoot ( router , RootCmp ) ;
15861609
1587- router . navigateByUrl ( '/team/33' ) ;
1588- advance ( fixture ) ;
1589- expect ( location . path ( ) ) . toEqual ( '/team/22' ) ;
1590- } ) ) ) ;
1610+ router . resetConfig (
1611+ [ { path : 'team/:id' , component : TeamCmp , canDeactivate : [ 'CanDeactivate' ] } ] ) ;
1612+
1613+ router . navigateByUrl ( '/team/22' ) ;
1614+ advance ( fixture ) ;
1615+ expect ( location . path ( ) ) . toEqual ( '/team/22' ) ;
1616+
1617+ router . navigateByUrl ( '/team/33' ) ;
1618+ advance ( fixture ) ;
1619+ expect ( location . path ( ) ) . toEqual ( '/team/22' ) ;
1620+ } ) ) ) ;
1621+ } ) ;
15911622 } ) ;
15921623 } ) ;
15931624
@@ -1826,6 +1857,7 @@ describe('Integration', () => {
18261857
18271858 TestBed . configureTestingModule ( { declarations : [ RootCmpWithLink ] } ) ;
18281859 const router : Router = TestBed . get ( Router ) ;
1860+ const loc : any = TestBed . get ( Location ) ;
18291861
18301862 const f = TestBed . createComponent ( RootCmpWithLink ) ;
18311863 advance ( f ) ;
0 commit comments