@@ -10,6 +10,7 @@ import { Schema as ApplicationOptions } from '../application/schema';
1010import { Schema as WorkspaceOptions } from '../workspace/schema' ;
1111import { Schema as ModuleOptions } from './schema' ;
1212
13+ // tslint:disable-next-line: no-big-function
1314describe ( 'Module Schematic' , ( ) => {
1415 const schematicRunner = new SchematicTestRunner (
1516 '@schematics/angular' ,
@@ -129,11 +130,13 @@ describe('Module Schematic', () => {
129130 const tree = await schematicRunner . runSchematicAsync ( 'module' , options , appTree ) . toPromise ( ) ;
130131 const files = tree . files ;
131132
132- expect ( files ) . toContain ( '/projects/bar/src/app/foo/foo.module.ts' ) ;
133- expect ( files ) . toContain ( '/projects/bar/src/app/foo/foo-routing.module.ts' ) ;
134- expect ( files ) . toContain ( '/projects/bar/src/app/foo/foo.component.ts' ) ;
135- expect ( files ) . toContain ( '/projects/bar/src/app/foo/foo.component.html' ) ;
136- expect ( files ) . toContain ( '/projects/bar/src/app/foo/foo.component.css' ) ;
133+ expect ( files ) . toEqual ( jasmine . arrayContaining ( [
134+ '/projects/bar/src/app/foo/foo.module.ts' ,
135+ '/projects/bar/src/app/foo/foo-routing.module.ts' ,
136+ '/projects/bar/src/app/foo/foo.component.ts' ,
137+ '/projects/bar/src/app/foo/foo.component.html' ,
138+ '/projects/bar/src/app/foo/foo.component.css' ,
139+ ] ) ) ;
137140
138141 const appRoutingModuleContent = tree . readContent ( '/projects/bar/src/app/app-routing.module.ts' ) ;
139142 expect ( appRoutingModuleContent ) . toMatch (
@@ -196,16 +199,55 @@ describe('Module Schematic', () => {
196199 ) . toPromise ( ) ;
197200 const files = tree . files ;
198201
199- expect ( files ) . toContain ( '/projects/bar/src/app/foo.module.ts' ) ;
200- expect ( files ) . toContain ( '/projects/bar/src/app/foo-routing.module.ts' ) ;
201- expect ( files ) . toContain ( '/projects/bar/src/app/foo.component.ts' ) ;
202- expect ( files ) . toContain ( '/projects/bar/src/app/foo.component.html' ) ;
203- expect ( files ) . toContain ( '/projects/bar/src/app/foo.component.css' ) ;
202+ expect ( files ) . toEqual ( jasmine . arrayContaining ( [
203+ '/projects/bar/src/app/foo.module.ts' ,
204+ '/projects/bar/src/app/foo-routing.module.ts' ,
205+ '/projects/bar/src/app/foo.component.ts' ,
206+ '/projects/bar/src/app/foo.component.html' ,
207+ '/projects/bar/src/app/foo.component.css' ,
208+ ] ) ) ;
204209
205210 const appRoutingModuleContent = tree . readContent ( '/projects/bar/src/app/app-routing.module.ts' ) ;
206211 expect ( appRoutingModuleContent ) . toMatch (
207212 / p a t h : ' \/ n e w - r o u t e ' , l o a d C h i l d r e n : \( \) = > i m p o r t \( ' .\/ f o o .m o d u l e ' \) .t h e n \( m = > m .F o o M o d u l e \) / ,
208213 ) ;
209214 } ) ;
215+
216+ it ( 'should generate a lazy loaded module and add route in another parallel routing module' , async ( ) => {
217+ await schematicRunner . runSchematicAsync (
218+ 'module' ,
219+ {
220+ ...defaultOptions ,
221+ name : 'foo' ,
222+ routing : true ,
223+ } ,
224+ appTree ,
225+ ) . toPromise ( ) ;
226+
227+ const tree = await schematicRunner . runSchematicAsync (
228+ 'module' ,
229+ {
230+ ...defaultOptions ,
231+ name : 'bar' ,
232+ module : 'foo' ,
233+ route : 'new-route' ,
234+ } ,
235+ appTree ,
236+ ) . toPromise ( ) ;
237+
238+ expect ( tree . files ) . toEqual ( jasmine . arrayContaining ( [
239+ '/projects/bar/src/app/foo/foo-routing.module.ts' ,
240+ '/projects/bar/src/app/foo/foo.module.ts' ,
241+ '/projects/bar/src/app/bar/bar-routing.module.ts' ,
242+ '/projects/bar/src/app/bar/bar.module.ts' ,
243+ '/projects/bar/src/app/bar/bar.component.ts' ,
244+ ] ) ) ;
245+
246+ const barRoutingModuleContent = tree . readContent ( '/projects/bar/src/app/bar/bar-routing.module.ts' ) ;
247+ expect ( barRoutingModuleContent ) . toContain ( `path: '', component: BarComponent ` ) ;
248+
249+ const fooRoutingModuleContent = tree . readContent ( '/projects/bar/src/app/foo/foo-routing.module.ts' ) ;
250+ expect ( fooRoutingModuleContent ) . toContain ( `loadChildren: () => import('../bar/bar.module').then(m => m.BarModule)` ) ;
251+ } ) ;
210252 } ) ;
211253} ) ;
0 commit comments