@@ -51,40 +51,62 @@ describe('Guard Schematic', () => {
51
51
) ;
52
52
53
53
const files = tree . files ;
54
- expect ( files ) . toContain ( '/projects/bar/src/app/foo. guard.spec.ts' ) ;
55
- expect ( files ) . toContain ( '/projects/bar/src/app/foo. guard.ts' ) ;
54
+ expect ( files ) . toContain ( '/projects/bar/src/app/foo- guard.spec.ts' ) ;
55
+ expect ( files ) . toContain ( '/projects/bar/src/app/foo- guard.ts' ) ;
56
56
} ) ;
57
57
58
58
it ( 'should respect the skipTests flag' , async ( ) => {
59
59
const options = { ...defaultOptions , skipTests : true } ;
60
60
61
61
const tree = await schematicRunner . runSchematic ( 'guard' , options , appTree ) ;
62
62
const files = tree . files ;
63
- expect ( files ) . not . toContain ( '/projects/bar/src/app/foo.guard.spec.ts' ) ;
63
+ expect ( files ) . not . toContain ( '/projects/bar/src/app/foo-guard.spec.ts' ) ;
64
+ expect ( files ) . toContain ( '/projects/bar/src/app/foo-guard.ts' ) ;
65
+ } ) ;
66
+
67
+ it ( 'should use a `.` type separator when specified' , async ( ) => {
68
+ const options = { ...defaultOptions , typeSeparator : '.' } ;
69
+
70
+ const tree = await schematicRunner . runSchematic ( 'guard' , options , appTree ) ;
71
+ const files = tree . files ;
72
+ expect ( files ) . toContain ( '/projects/bar/src/app/foo.guard.spec.ts' ) ;
64
73
expect ( files ) . toContain ( '/projects/bar/src/app/foo.guard.ts' ) ;
74
+ const specContent = tree . readContent ( '/projects/bar/src/app/foo.guard.spec.ts' ) ;
75
+ expect ( specContent ) . toContain ( `'./foo.guard'` ) ;
76
+ } ) ;
77
+
78
+ it ( 'should use a `-` type separator when specified' , async ( ) => {
79
+ const options = { ...defaultOptions , typeSeparator : '-' } ;
80
+
81
+ const tree = await schematicRunner . runSchematic ( 'guard' , options , appTree ) ;
82
+ const files = tree . files ;
83
+ expect ( files ) . toContain ( '/projects/bar/src/app/foo-guard.spec.ts' ) ;
84
+ expect ( files ) . toContain ( '/projects/bar/src/app/foo-guard.ts' ) ;
85
+ const specContent = tree . readContent ( '/projects/bar/src/app/foo-guard.spec.ts' ) ;
86
+ expect ( specContent ) . toContain ( `'./foo-guard'` ) ;
65
87
} ) ;
66
88
67
89
it ( 'should respect the flat flag' , async ( ) => {
68
90
const options = { ...defaultOptions , flat : false } ;
69
91
70
92
const tree = await schematicRunner . runSchematic ( 'guard' , options , appTree ) ;
71
93
const files = tree . files ;
72
- expect ( files ) . toContain ( '/projects/bar/src/app/foo/foo. guard.spec.ts' ) ;
73
- expect ( files ) . toContain ( '/projects/bar/src/app/foo/foo. guard.ts' ) ;
94
+ expect ( files ) . toContain ( '/projects/bar/src/app/foo/foo- guard.spec.ts' ) ;
95
+ expect ( files ) . toContain ( '/projects/bar/src/app/foo/foo- guard.ts' ) ;
74
96
} ) ;
75
97
76
98
it ( 'should respect the sourceRoot value' , async ( ) => {
77
99
const config = JSON . parse ( appTree . readContent ( '/angular.json' ) ) ;
78
100
config . projects . bar . sourceRoot = 'projects/bar/custom' ;
79
101
appTree . overwrite ( '/angular.json' , JSON . stringify ( config , null , 2 ) ) ;
80
102
appTree = await schematicRunner . runSchematic ( 'guard' , defaultOptions , appTree ) ;
81
- expect ( appTree . files ) . toContain ( '/projects/bar/custom/app/foo. guard.ts' ) ;
103
+ expect ( appTree . files ) . toContain ( '/projects/bar/custom/app/foo- guard.ts' ) ;
82
104
} ) ;
83
105
84
106
it ( 'should respect the implements value' , async ( ) => {
85
107
const options = { ...defaultOptions , implements : [ 'CanActivate' ] , functional : false } ;
86
108
const tree = await schematicRunner . runSchematic ( 'guard' , options , appTree ) ;
87
- const fileString = tree . readContent ( '/projects/bar/src/app/foo. guard.ts' ) ;
109
+ const fileString = tree . readContent ( '/projects/bar/src/app/foo- guard.ts' ) ;
88
110
expect ( fileString ) . toContain ( 'CanActivate' ) ;
89
111
expect ( fileString ) . toContain ( 'canActivate' ) ;
90
112
expect ( fileString ) . not . toContain ( 'CanActivateChild' ) ;
@@ -96,7 +118,7 @@ describe('Guard Schematic', () => {
96
118
it ( 'should generate a functional guard by default' , async ( ) => {
97
119
const options = { ...defaultOptions , implements : [ 'CanActivate' ] } ;
98
120
const tree = await schematicRunner . runSchematic ( 'guard' , options , appTree ) ;
99
- const fileString = tree . readContent ( '/projects/bar/src/app/foo. guard.ts' ) ;
121
+ const fileString = tree . readContent ( '/projects/bar/src/app/foo- guard.ts' ) ;
100
122
expect ( fileString ) . toContain ( 'export const fooGuard: CanActivateFn = (route, state) => {' ) ;
101
123
expect ( fileString ) . not . toContain ( 'CanActivateChild' ) ;
102
124
expect ( fileString ) . not . toContain ( 'canActivateChild' ) ;
@@ -107,7 +129,7 @@ describe('Guard Schematic', () => {
107
129
it ( 'should generate a helper function to execute the guard in a test' , async ( ) => {
108
130
const options = { ...defaultOptions , implements : [ 'CanActivate' ] } ;
109
131
const tree = await schematicRunner . runSchematic ( 'guard' , options , appTree ) ;
110
- const fileString = tree . readContent ( '/projects/bar/src/app/foo. guard.spec.ts' ) ;
132
+ const fileString = tree . readContent ( '/projects/bar/src/app/foo- guard.spec.ts' ) ;
111
133
expect ( fileString ) . toContain ( 'const executeGuard: CanActivateFn = (...guardParameters) => ' ) ;
112
134
expect ( fileString ) . toContain (
113
135
'TestBed.runInInjectionContext(() => fooGuard(...guardParameters));' ,
@@ -117,7 +139,7 @@ describe('Guard Schematic', () => {
117
139
it ( 'should generate CanDeactivateFn with unknown functional guard' , async ( ) => {
118
140
const options = { ...defaultOptions , implements : [ 'CanDeactivate' ] } ;
119
141
const tree = await schematicRunner . runSchematic ( 'guard' , options , appTree ) ;
120
- const fileString = tree . readContent ( '/projects/bar/src/app/foo. guard.ts' ) ;
142
+ const fileString = tree . readContent ( '/projects/bar/src/app/foo- guard.ts' ) ;
121
143
expect ( fileString ) . toContain (
122
144
'export const fooGuard: CanDeactivateFn<unknown> = ' +
123
145
'(component, currentRoute, currentState, nextState) => {' ,
@@ -128,7 +150,7 @@ describe('Guard Schematic', () => {
128
150
const implementationOptions = [ 'CanActivate' , 'CanDeactivate' , 'CanActivateChild' ] ;
129
151
const options = { ...defaultOptions , implements : implementationOptions , functional : false } ;
130
152
const tree = await schematicRunner . runSchematic ( 'guard' , options , appTree ) ;
131
- const fileString = tree . readContent ( '/projects/bar/src/app/foo. guard.ts' ) ;
153
+ const fileString = tree . readContent ( '/projects/bar/src/app/foo- guard.ts' ) ;
132
154
133
155
// Should contain all implementations
134
156
implementationOptions . forEach ( ( implementation : string ) => {
@@ -142,7 +164,7 @@ describe('Guard Schematic', () => {
142
164
const implementationOptions = [ 'CanMatch' ] ;
143
165
const options = { ...defaultOptions , implements : implementationOptions , functional : false } ;
144
166
const tree = await schematicRunner . runSchematic ( 'guard' , options , appTree ) ;
145
- const fileString = tree . readContent ( '/projects/bar/src/app/foo. guard.ts' ) ;
167
+ const fileString = tree . readContent ( '/projects/bar/src/app/foo- guard.ts' ) ;
146
168
const expectedImports = `import { CanMatch, GuardResult, MaybeAsync, Route, subPath } from '@angular/router';` ;
147
169
148
170
expect ( fileString ) . toContain ( expectedImports ) ;
@@ -152,7 +174,7 @@ describe('Guard Schematic', () => {
152
174
const implementationOptions = [ 'CanActivate' ] ;
153
175
const options = { ...defaultOptions , implements : implementationOptions , functional : false } ;
154
176
const tree = await schematicRunner . runSchematic ( 'guard' , options , appTree ) ;
155
- const fileString = tree . readContent ( '/projects/bar/src/app/foo. guard.ts' ) ;
177
+ const fileString = tree . readContent ( '/projects/bar/src/app/foo- guard.ts' ) ;
156
178
const expectedImports =
157
179
`import { ActivatedRouteSnapshot, CanActivate, GuardResult, ` +
158
180
`MaybeAsync, RouterStateSnapshot } from '@angular/router';` ;
@@ -163,7 +185,7 @@ describe('Guard Schematic', () => {
163
185
it ( 'should add correct imports based on canActivate functional guard' , async ( ) => {
164
186
const options = { ...defaultOptions , implements : [ 'CanActivate' ] } ;
165
187
const tree = await schematicRunner . runSchematic ( 'guard' , options , appTree ) ;
166
- const fileString = tree . readContent ( '/projects/bar/src/app/foo. guard.ts' ) ;
188
+ const fileString = tree . readContent ( '/projects/bar/src/app/foo- guard.ts' ) ;
167
189
const expectedImports = `import { CanActivateFn } from '@angular/router';` ;
168
190
169
191
expect ( fileString ) . toContain ( expectedImports ) ;
@@ -173,7 +195,7 @@ describe('Guard Schematic', () => {
173
195
const implementationOptions = [ 'CanActivate' , 'CanMatch' , 'CanActivateChild' ] ;
174
196
const options = { ...defaultOptions , implements : implementationOptions , functional : false } ;
175
197
const tree = await schematicRunner . runSchematic ( 'guard' , options , appTree ) ;
176
- const fileString = tree . readContent ( '/projects/bar/src/app/foo. guard.ts' ) ;
198
+ const fileString = tree . readContent ( '/projects/bar/src/app/foo- guard.ts' ) ;
177
199
const expectedImports =
178
200
`import { ActivatedRouteSnapshot, CanActivate, CanActivateChild, CanMatch, GuardResult, ` +
179
201
`MaybeAsync, Route, RouterStateSnapshot, subPath } from '@angular/router';` ;
0 commit comments