@@ -51,40 +51,62 @@ describe('Guard Schematic', () => {
5151 ) ;
5252
5353 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' ) ;
5656 } ) ;
5757
5858 it ( 'should respect the skipTests flag' , async ( ) => {
5959 const options = { ...defaultOptions , skipTests : true } ;
6060
6161 const tree = await schematicRunner . runSchematic ( 'guard' , options , appTree ) ;
6262 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' ) ;
6473 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'` ) ;
6587 } ) ;
6688
6789 it ( 'should respect the flat flag' , async ( ) => {
6890 const options = { ...defaultOptions , flat : false } ;
6991
7092 const tree = await schematicRunner . runSchematic ( 'guard' , options , appTree ) ;
7193 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' ) ;
7496 } ) ;
7597
7698 it ( 'should respect the sourceRoot value' , async ( ) => {
7799 const config = JSON . parse ( appTree . readContent ( '/angular.json' ) ) ;
78100 config . projects . bar . sourceRoot = 'projects/bar/custom' ;
79101 appTree . overwrite ( '/angular.json' , JSON . stringify ( config , null , 2 ) ) ;
80102 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' ) ;
82104 } ) ;
83105
84106 it ( 'should respect the implements value' , async ( ) => {
85107 const options = { ...defaultOptions , implements : [ 'CanActivate' ] , functional : false } ;
86108 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' ) ;
88110 expect ( fileString ) . toContain ( 'CanActivate' ) ;
89111 expect ( fileString ) . toContain ( 'canActivate' ) ;
90112 expect ( fileString ) . not . toContain ( 'CanActivateChild' ) ;
@@ -96,7 +118,7 @@ describe('Guard Schematic', () => {
96118 it ( 'should generate a functional guard by default' , async ( ) => {
97119 const options = { ...defaultOptions , implements : [ 'CanActivate' ] } ;
98120 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' ) ;
100122 expect ( fileString ) . toContain ( 'export const fooGuard: CanActivateFn = (route, state) => {' ) ;
101123 expect ( fileString ) . not . toContain ( 'CanActivateChild' ) ;
102124 expect ( fileString ) . not . toContain ( 'canActivateChild' ) ;
@@ -107,7 +129,7 @@ describe('Guard Schematic', () => {
107129 it ( 'should generate a helper function to execute the guard in a test' , async ( ) => {
108130 const options = { ...defaultOptions , implements : [ 'CanActivate' ] } ;
109131 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' ) ;
111133 expect ( fileString ) . toContain ( 'const executeGuard: CanActivateFn = (...guardParameters) => ' ) ;
112134 expect ( fileString ) . toContain (
113135 'TestBed.runInInjectionContext(() => fooGuard(...guardParameters));' ,
@@ -117,7 +139,7 @@ describe('Guard Schematic', () => {
117139 it ( 'should generate CanDeactivateFn with unknown functional guard' , async ( ) => {
118140 const options = { ...defaultOptions , implements : [ 'CanDeactivate' ] } ;
119141 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' ) ;
121143 expect ( fileString ) . toContain (
122144 'export const fooGuard: CanDeactivateFn<unknown> = ' +
123145 '(component, currentRoute, currentState, nextState) => {' ,
@@ -128,7 +150,7 @@ describe('Guard Schematic', () => {
128150 const implementationOptions = [ 'CanActivate' , 'CanDeactivate' , 'CanActivateChild' ] ;
129151 const options = { ...defaultOptions , implements : implementationOptions , functional : false } ;
130152 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' ) ;
132154
133155 // Should contain all implementations
134156 implementationOptions . forEach ( ( implementation : string ) => {
@@ -142,7 +164,7 @@ describe('Guard Schematic', () => {
142164 const implementationOptions = [ 'CanMatch' ] ;
143165 const options = { ...defaultOptions , implements : implementationOptions , functional : false } ;
144166 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' ) ;
146168 const expectedImports = `import { CanMatch, GuardResult, MaybeAsync, Route, subPath } from '@angular/router';` ;
147169
148170 expect ( fileString ) . toContain ( expectedImports ) ;
@@ -152,7 +174,7 @@ describe('Guard Schematic', () => {
152174 const implementationOptions = [ 'CanActivate' ] ;
153175 const options = { ...defaultOptions , implements : implementationOptions , functional : false } ;
154176 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' ) ;
156178 const expectedImports =
157179 `import { ActivatedRouteSnapshot, CanActivate, GuardResult, ` +
158180 `MaybeAsync, RouterStateSnapshot } from '@angular/router';` ;
@@ -163,7 +185,7 @@ describe('Guard Schematic', () => {
163185 it ( 'should add correct imports based on canActivate functional guard' , async ( ) => {
164186 const options = { ...defaultOptions , implements : [ 'CanActivate' ] } ;
165187 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' ) ;
167189 const expectedImports = `import { CanActivateFn } from '@angular/router';` ;
168190
169191 expect ( fileString ) . toContain ( expectedImports ) ;
@@ -173,7 +195,7 @@ describe('Guard Schematic', () => {
173195 const implementationOptions = [ 'CanActivate' , 'CanMatch' , 'CanActivateChild' ] ;
174196 const options = { ...defaultOptions , implements : implementationOptions , functional : false } ;
175197 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' ) ;
177199 const expectedImports =
178200 `import { ActivatedRouteSnapshot, CanActivate, CanActivateChild, CanMatch, GuardResult, ` +
179201 `MaybeAsync, Route, RouterStateSnapshot, subPath } from '@angular/router';` ;
0 commit comments