File tree 2 files changed +21
-8
lines changed
packages/schematics/angular/guard
2 files changed +21
-8
lines changed Original file line number Diff line number Diff line change 8
8
import { strings } from '@angular-devkit/core' ;
9
9
import {
10
10
Rule ,
11
- SchematicsException ,
12
11
Tree ,
13
12
apply ,
14
13
applyTemplates ,
@@ -37,13 +36,14 @@ export default function (options: GuardOptions): Rule {
37
36
38
37
let implementations = '' ;
39
38
let implementationImports = '' ;
40
- if ( options . implements . length > 0 ) {
41
- implementations = options . implements . join ( ', ' ) ;
42
- implementationImports = `${ implementations } , ` ;
43
- // As long as we aren't in IE... ;)
44
- if ( options . implements . includes ( 'CanLoad' ) ) {
45
- implementationImports = `${ implementationImports } Route, UrlSegment, ` ;
46
- }
39
+ if ( options . implements . length === 0 ) {
40
+ options . implements . push ( 'CanActivate' ) ;
41
+ }
42
+ implementations = options . implements . join ( ', ' ) ;
43
+ implementationImports = `${ implementations } , ` ;
44
+ // As long as we aren't in IE... ;)
45
+ if ( options . implements . includes ( 'CanLoad' ) ) {
46
+ implementationImports = `${ implementationImports } Route, UrlSegment, ` ;
47
47
}
48
48
49
49
const parsedPath = parseName ( options . path , options . name ) ;
Original file line number Diff line number Diff line change @@ -105,4 +105,17 @@ describe('Guard Schematic', () => {
105
105
expect ( fileString ) . toContain ( functionName ) ;
106
106
} ) ;
107
107
} ) ;
108
+
109
+ it ( 'should use CanActivate if no implements value' , async ( ) => {
110
+ const options = { ...defaultOptions , implements : [ ] } ;
111
+ const tree = await schematicRunner . runSchematicAsync ( 'guard' , options , appTree )
112
+ . toPromise ( ) ;
113
+ const fileString = tree . readContent ( '/projects/bar/src/app/foo.guard.ts' ) ;
114
+ expect ( fileString ) . toContain ( 'CanActivate' ) ;
115
+ expect ( fileString ) . toContain ( 'canActivate' ) ;
116
+ expect ( fileString ) . not . toContain ( 'CanActivateChild' ) ;
117
+ expect ( fileString ) . not . toContain ( 'canActivateChild' ) ;
118
+ expect ( fileString ) . not . toContain ( 'CanLoad' ) ;
119
+ expect ( fileString ) . not . toContain ( 'canLoad' ) ;
120
+ } ) ;
108
121
} ) ;
You can’t perform that action at this time.
0 commit comments