@@ -1647,6 +1647,69 @@ describe('Integration', () => {
16471647 expect ( location . path ( ) ) . toEqual ( '/simple' ) ;
16481648 } ) ) ) ;
16491649
1650+ describe ( 'next state' , ( ) => {
1651+ let log : string [ ] ;
1652+
1653+ class ClassWithNextState implements CanDeactivate < TeamCmp > {
1654+ canDeactivate (
1655+ component : TeamCmp , currentRoute : ActivatedRouteSnapshot ,
1656+ currentState : RouterStateSnapshot , nextState : RouterStateSnapshot ) : boolean {
1657+ log . push ( currentState . url , nextState . url ) ;
1658+ return true ;
1659+ }
1660+ }
1661+
1662+ beforeEach ( ( ) => {
1663+ log = [ ] ;
1664+ TestBed . configureTestingModule ( {
1665+ providers : [
1666+ ClassWithNextState , {
1667+ provide : 'FunctionWithNextState' ,
1668+ useValue : ( cmp : any , currentRoute : ActivatedRouteSnapshot ,
1669+ currentState : RouterStateSnapshot , nextState : RouterStateSnapshot ) => {
1670+ log . push ( currentState . url , nextState . url ) ;
1671+ return true ;
1672+ }
1673+ }
1674+ ]
1675+ } ) ;
1676+ } ) ;
1677+
1678+ it ( 'should pass next state as the 4 argument when guard is a class' ,
1679+ fakeAsync ( inject ( [ Router , Location ] , ( router : Router , location : Location ) => {
1680+ const fixture = createRoot ( router , RootCmp ) ;
1681+
1682+ router . resetConfig (
1683+ [ { path : 'team/:id' , component : TeamCmp , canDeactivate : [ ClassWithNextState ] } ] ) ;
1684+
1685+ router . navigateByUrl ( '/team/22' ) ;
1686+ advance ( fixture ) ;
1687+ expect ( location . path ( ) ) . toEqual ( '/team/22' ) ;
1688+
1689+ router . navigateByUrl ( '/team/33' ) ;
1690+ advance ( fixture ) ;
1691+ expect ( location . path ( ) ) . toEqual ( '/team/33' ) ;
1692+ expect ( log ) . toEqual ( [ '/team/22' , '/team/33' ] ) ;
1693+ } ) ) ) ;
1694+
1695+ it ( 'should pass next state as the 4 argument when guard is a function' ,
1696+ fakeAsync ( inject ( [ Router , Location ] , ( router : Router , location : Location ) => {
1697+ const fixture = createRoot ( router , RootCmp ) ;
1698+
1699+ router . resetConfig ( [
1700+ { path : 'team/:id' , component : TeamCmp , canDeactivate : [ 'FunctionWithNextState' ] }
1701+ ] ) ;
1702+
1703+ router . navigateByUrl ( '/team/22' ) ;
1704+ advance ( fixture ) ;
1705+ expect ( location . path ( ) ) . toEqual ( '/team/22' ) ;
1706+
1707+ router . navigateByUrl ( '/team/33' ) ;
1708+ advance ( fixture ) ;
1709+ expect ( location . path ( ) ) . toEqual ( '/team/33' ) ;
1710+ expect ( log ) . toEqual ( [ '/team/22' , '/team/33' ] ) ;
1711+ } ) ) ) ;
1712+ } ) ;
16501713
16511714 describe ( 'should work when given a class' , ( ) => {
16521715 class AlwaysTrue implements CanDeactivate < TeamCmp > {
0 commit comments