@@ -43,8 +43,12 @@ describe('Guard Schematic', () => {
43
43
appTree = await schematicRunner . runSchematic ( 'application' , appOptions , appTree ) ;
44
44
} ) ;
45
45
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
+ ) ;
48
52
49
53
const files = tree . files ;
50
54
expect ( files ) . toContain ( '/projects/bar/src/app/foo.guard.spec.ts' ) ;
@@ -78,7 +82,7 @@ describe('Guard Schematic', () => {
78
82
} ) ;
79
83
80
84
it ( 'should respect the implements value' , async ( ) => {
81
- const options = { ...defaultOptions , implements : [ 'CanActivate' ] } ;
85
+ const options = { ...defaultOptions , implements : [ 'CanActivate' ] , functional : false } ;
82
86
const tree = await schematicRunner . runSchematic ( 'guard' , options , appTree ) ;
83
87
const fileString = tree . readContent ( '/projects/bar/src/app/foo.guard.ts' ) ;
84
88
expect ( fileString ) . toContain ( 'CanActivate' ) ;
@@ -89,8 +93,8 @@ describe('Guard Schematic', () => {
89
93
expect ( fileString ) . not . toContain ( 'canMatch' ) ;
90
94
} ) ;
91
95
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' ] } ;
94
98
const tree = await schematicRunner . runSchematic ( 'guard' , options , appTree ) ;
95
99
const fileString = tree . readContent ( '/projects/bar/src/app/foo.guard.ts' ) ;
96
100
expect ( fileString ) . toContain ( 'export const fooGuard: CanActivateFn = (route, state) => {' ) ;
@@ -101,7 +105,7 @@ describe('Guard Schematic', () => {
101
105
} ) ;
102
106
103
107
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' ] } ;
105
109
const tree = await schematicRunner . runSchematic ( 'guard' , options , appTree ) ;
106
110
const fileString = tree . readContent ( '/projects/bar/src/app/foo.guard.spec.ts' ) ;
107
111
expect ( fileString ) . toContain ( 'const executeGuard: CanActivateFn = (...guardParameters) => ' ) ;
@@ -111,7 +115,7 @@ describe('Guard Schematic', () => {
111
115
} ) ;
112
116
113
117
it ( 'should generate CanDeactivateFn with unknown functional guard' , async ( ) => {
114
- const options = { ...defaultOptions , implements : [ 'CanDeactivate' ] , functional : true } ;
118
+ const options = { ...defaultOptions , implements : [ 'CanDeactivate' ] } ;
115
119
const tree = await schematicRunner . runSchematic ( 'guard' , options , appTree ) ;
116
120
const fileString = tree . readContent ( '/projects/bar/src/app/foo.guard.ts' ) ;
117
121
expect ( fileString ) . toContain (
@@ -120,9 +124,9 @@ describe('Guard Schematic', () => {
120
124
) ;
121
125
} ) ;
122
126
123
- it ( 'should respect the implements values' , async ( ) => {
127
+ it ( 'should respect the implements values in (deprecated) class-based guards ' , async ( ) => {
124
128
const implementationOptions = [ 'CanActivate' , 'CanDeactivate' , 'CanActivateChild' ] ;
125
- const options = { ...defaultOptions , implements : implementationOptions } ;
129
+ const options = { ...defaultOptions , implements : implementationOptions , functional : false } ;
126
130
const tree = await schematicRunner . runSchematic ( 'guard' , options , appTree ) ;
127
131
const fileString = tree . readContent ( '/projects/bar/src/app/foo.guard.ts' ) ;
128
132
@@ -134,19 +138,19 @@ describe('Guard Schematic', () => {
134
138
} ) ;
135
139
} ) ;
136
140
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 ( ) => {
138
142
const implementationOptions = [ 'CanMatch' ] ;
139
- const options = { ...defaultOptions , implements : implementationOptions } ;
143
+ const options = { ...defaultOptions , implements : implementationOptions , functional : false } ;
140
144
const tree = await schematicRunner . runSchematic ( 'guard' , options , appTree ) ;
141
145
const fileString = tree . readContent ( '/projects/bar/src/app/foo.guard.ts' ) ;
142
146
const expectedImports = `import { CanMatch, Route, UrlSegment, UrlTree } from '@angular/router';` ;
143
147
144
148
expect ( fileString ) . toContain ( expectedImports ) ;
145
149
} ) ;
146
150
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 ( ) => {
148
152
const implementationOptions = [ 'CanActivate' ] ;
149
- const options = { ...defaultOptions , implements : implementationOptions } ;
153
+ const options = { ...defaultOptions , implements : implementationOptions , functional : false } ;
150
154
const tree = await schematicRunner . runSchematic ( 'guard' , options , appTree ) ;
151
155
const fileString = tree . readContent ( '/projects/bar/src/app/foo.guard.ts' ) ;
152
156
const expectedImports = `import { ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot, UrlTree } from '@angular/router';` ;
@@ -155,17 +159,17 @@ describe('Guard Schematic', () => {
155
159
} ) ;
156
160
157
161
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' ] } ;
159
163
const tree = await schematicRunner . runSchematic ( 'guard' , options , appTree ) ;
160
164
const fileString = tree . readContent ( '/projects/bar/src/app/foo.guard.ts' ) ;
161
165
const expectedImports = `import { CanActivateFn } from '@angular/router';` ;
162
166
163
167
expect ( fileString ) . toContain ( expectedImports ) ;
164
168
} ) ;
165
169
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 ( ) => {
167
171
const implementationOptions = [ 'CanActivate' , 'CanMatch' , 'CanActivateChild' ] ;
168
- const options = { ...defaultOptions , implements : implementationOptions } ;
172
+ const options = { ...defaultOptions , implements : implementationOptions , functional : false } ;
169
173
const tree = await schematicRunner . runSchematic ( 'guard' , options , appTree ) ;
170
174
const fileString = tree . readContent ( '/projects/bar/src/app/foo.guard.ts' ) ;
171
175
const expectedImports =
0 commit comments