@@ -43,8 +43,12 @@ describe('Guard Schematic', () => {
4343 appTree = await schematicRunner . runSchematic ( 'application' , appOptions , appTree ) ;
4444 } ) ;
4545
46- it ( 'should create a guard' , async ( ) => {
47- const tree = await schematicRunner . runSchematic ( 'guard' , defaultOptions , appTree ) ;
46+ it ( 'should create a (deprecated) class-based guard with --no-functional' , async ( ) => {
47+ const tree = await schematicRunner . runSchematic (
48+ 'guard' ,
49+ { ...defaultOptions , functional : false } ,
50+ appTree ,
51+ ) ;
4852
4953 const files = tree . files ;
5054 expect ( files ) . toContain ( '/projects/bar/src/app/foo.guard.spec.ts' ) ;
@@ -78,7 +82,7 @@ describe('Guard Schematic', () => {
7882 } ) ;
7983
8084 it ( 'should respect the implements value' , async ( ) => {
81- const options = { ...defaultOptions , implements : [ 'CanActivate' ] } ;
85+ const options = { ...defaultOptions , implements : [ 'CanActivate' ] , functional : false } ;
8286 const tree = await schematicRunner . runSchematic ( 'guard' , options , appTree ) ;
8387 const fileString = tree . readContent ( '/projects/bar/src/app/foo.guard.ts' ) ;
8488 expect ( fileString ) . toContain ( 'CanActivate' ) ;
@@ -89,8 +93,8 @@ describe('Guard Schematic', () => {
8993 expect ( fileString ) . not . toContain ( 'canMatch' ) ;
9094 } ) ;
9195
92- it ( 'should respect the functional guard value ' , async ( ) => {
93- const options = { ...defaultOptions , implements : [ 'CanActivate' ] , functional : true } ;
96+ it ( 'should generate a functional guard by default ' , async ( ) => {
97+ const options = { ...defaultOptions , implements : [ 'CanActivate' ] } ;
9498 const tree = await schematicRunner . runSchematic ( 'guard' , options , appTree ) ;
9599 const fileString = tree . readContent ( '/projects/bar/src/app/foo.guard.ts' ) ;
96100 expect ( fileString ) . toContain ( 'export const fooGuard: CanActivateFn = (route, state) => {' ) ;
@@ -101,7 +105,7 @@ describe('Guard Schematic', () => {
101105 } ) ;
102106
103107 it ( 'should generate a helper function to execute the guard in a test' , async ( ) => {
104- const options = { ...defaultOptions , implements : [ 'CanActivate' ] , functional : true } ;
108+ const options = { ...defaultOptions , implements : [ 'CanActivate' ] } ;
105109 const tree = await schematicRunner . runSchematic ( 'guard' , options , appTree ) ;
106110 const fileString = tree . readContent ( '/projects/bar/src/app/foo.guard.spec.ts' ) ;
107111 expect ( fileString ) . toContain ( 'const executeGuard: CanActivateFn = (...guardParameters) => ' ) ;
@@ -111,7 +115,7 @@ describe('Guard Schematic', () => {
111115 } ) ;
112116
113117 it ( 'should generate CanDeactivateFn with unknown functional guard' , async ( ) => {
114- const options = { ...defaultOptions , implements : [ 'CanDeactivate' ] , functional : true } ;
118+ const options = { ...defaultOptions , implements : [ 'CanDeactivate' ] } ;
115119 const tree = await schematicRunner . runSchematic ( 'guard' , options , appTree ) ;
116120 const fileString = tree . readContent ( '/projects/bar/src/app/foo.guard.ts' ) ;
117121 expect ( fileString ) . toContain (
@@ -120,9 +124,9 @@ describe('Guard Schematic', () => {
120124 ) ;
121125 } ) ;
122126
123- it ( 'should respect the implements values' , async ( ) => {
127+ it ( 'should respect the implements values in (deprecated) class-based guards ' , async ( ) => {
124128 const implementationOptions = [ 'CanActivate' , 'CanDeactivate' , 'CanActivateChild' ] ;
125- const options = { ...defaultOptions , implements : implementationOptions } ;
129+ const options = { ...defaultOptions , implements : implementationOptions , functional : false } ;
126130 const tree = await schematicRunner . runSchematic ( 'guard' , options , appTree ) ;
127131 const fileString = tree . readContent ( '/projects/bar/src/app/foo.guard.ts' ) ;
128132
@@ -134,19 +138,19 @@ describe('Guard Schematic', () => {
134138 } ) ;
135139 } ) ;
136140
137- it ( 'should add correct imports based on CanMatch implementation' , async ( ) => {
141+ it ( 'should add correct imports based on CanMatch implementation in (deprecated) class-based guards ' , async ( ) => {
138142 const implementationOptions = [ 'CanMatch' ] ;
139- const options = { ...defaultOptions , implements : implementationOptions } ;
143+ const options = { ...defaultOptions , implements : implementationOptions , functional : false } ;
140144 const tree = await schematicRunner . runSchematic ( 'guard' , options , appTree ) ;
141145 const fileString = tree . readContent ( '/projects/bar/src/app/foo.guard.ts' ) ;
142146 const expectedImports = `import { CanMatch, Route, UrlSegment, UrlTree } from '@angular/router';` ;
143147
144148 expect ( fileString ) . toContain ( expectedImports ) ;
145149 } ) ;
146150
147- it ( 'should add correct imports based on CanActivate implementation' , async ( ) => {
151+ it ( 'should add correct imports based on CanActivate implementation in (deprecated) class-based guards ' , async ( ) => {
148152 const implementationOptions = [ 'CanActivate' ] ;
149- const options = { ...defaultOptions , implements : implementationOptions } ;
153+ const options = { ...defaultOptions , implements : implementationOptions , functional : false } ;
150154 const tree = await schematicRunner . runSchematic ( 'guard' , options , appTree ) ;
151155 const fileString = tree . readContent ( '/projects/bar/src/app/foo.guard.ts' ) ;
152156 const expectedImports = `import { ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot, UrlTree } from '@angular/router';` ;
@@ -155,17 +159,17 @@ describe('Guard Schematic', () => {
155159 } ) ;
156160
157161 it ( 'should add correct imports based on canActivate functional guard' , async ( ) => {
158- const options = { ...defaultOptions , implements : [ 'CanActivate' ] , functional : true } ;
162+ const options = { ...defaultOptions , implements : [ 'CanActivate' ] } ;
159163 const tree = await schematicRunner . runSchematic ( 'guard' , options , appTree ) ;
160164 const fileString = tree . readContent ( '/projects/bar/src/app/foo.guard.ts' ) ;
161165 const expectedImports = `import { CanActivateFn } from '@angular/router';` ;
162166
163167 expect ( fileString ) . toContain ( expectedImports ) ;
164168 } ) ;
165169
166- it ( 'should add correct imports if multiple implementations was selected' , async ( ) => {
170+ it ( 'should add correct imports if multiple implementations was selected in (deprecated) class-based guards ' , async ( ) => {
167171 const implementationOptions = [ 'CanActivate' , 'CanMatch' , 'CanActivateChild' ] ;
168- const options = { ...defaultOptions , implements : implementationOptions } ;
172+ const options = { ...defaultOptions , implements : implementationOptions , functional : false } ;
169173 const tree = await schematicRunner . runSchematic ( 'guard' , options , appTree ) ;
170174 const fileString = tree . readContent ( '/projects/bar/src/app/foo.guard.ts' ) ;
171175 const expectedImports =
0 commit comments