@@ -10,7 +10,6 @@ import { Schema as ApplicationOptions } from '../application/schema';
1010import { Schema as WorkspaceOptions } from '../workspace/schema' ;
1111import { Schema as GuardOptions } from './schema' ;
1212
13-
1413describe ( 'Guard Schematic' , ( ) => {
1514 const schematicRunner = new SchematicTestRunner (
1615 '@schematics/angular' ,
@@ -64,4 +63,30 @@ describe('Guard Schematic', () => {
6463 appTree = schematicRunner . runSchematic ( 'guard' , defaultOptions , appTree ) ;
6564 expect ( appTree . files ) . toContain ( '/projects/bar/custom/app/foo.guard.ts' ) ;
6665 } ) ;
66+
67+ it ( 'should respect the implements value' , ( ) => {
68+ const options = { ...defaultOptions , implements : [ 'CanActivate' ] } ;
69+ const tree = schematicRunner . runSchematic ( 'guard' , options , appTree ) ;
70+ const fileString = tree . readContent ( '/projects/bar/src/app/foo.guard.ts' ) ;
71+ expect ( fileString ) . toContain ( 'CanActivate' ) ;
72+ expect ( fileString ) . toContain ( 'canActivate' ) ;
73+ expect ( fileString ) . not . toContain ( 'CanActivateChild' ) ;
74+ expect ( fileString ) . not . toContain ( 'canActivateChild' ) ;
75+ expect ( fileString ) . not . toContain ( 'CanLoad' ) ;
76+ expect ( fileString ) . not . toContain ( 'canLoad' ) ;
77+ } ) ;
78+
79+ it ( 'should respect the implements values' , ( ) => {
80+ const implementationOptions = [ 'CanActivate' , 'CanLoad' , 'CanActivateChild' ] ;
81+ const options = { ...defaultOptions , implements : implementationOptions } ;
82+ const tree = schematicRunner . runSchematic ( 'guard' , options , appTree ) ;
83+ const fileString = tree . readContent ( '/projects/bar/src/app/foo.guard.ts' ) ;
84+
85+ // Should contain all implementations
86+ implementationOptions . forEach ( ( implementation : string ) => {
87+ expect ( fileString ) . toContain ( implementation ) ;
88+ const functionName = `${ implementation . charAt ( 0 ) . toLowerCase ( ) } ${ implementation . slice ( 1 ) } ` ;
89+ expect ( fileString ) . toContain ( functionName ) ;
90+ } ) ;
91+ } ) ;
6792} ) ;
0 commit comments