@@ -10,6 +10,7 @@ import { Schema as ApplicationOptions } from '../application/schema';
10
10
import { Schema as WorkspaceOptions } from '../workspace/schema' ;
11
11
import { Schema as ModuleOptions } from './schema' ;
12
12
13
+ // tslint:disable-next-line: no-big-function
13
14
describe ( 'Module Schematic' , ( ) => {
14
15
const schematicRunner = new SchematicTestRunner (
15
16
'@schematics/angular' ,
@@ -129,11 +130,13 @@ describe('Module Schematic', () => {
129
130
const tree = await schematicRunner . runSchematicAsync ( 'module' , options , appTree ) . toPromise ( ) ;
130
131
const files = tree . files ;
131
132
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
+ ] ) ) ;
137
140
138
141
const appRoutingModuleContent = tree . readContent ( '/projects/bar/src/app/app-routing.module.ts' ) ;
139
142
expect ( appRoutingModuleContent ) . toMatch (
@@ -196,16 +199,55 @@ describe('Module Schematic', () => {
196
199
) . toPromise ( ) ;
197
200
const files = tree . files ;
198
201
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
+ ] ) ) ;
204
209
205
210
const appRoutingModuleContent = tree . readContent ( '/projects/bar/src/app/app-routing.module.ts' ) ;
206
211
expect ( appRoutingModuleContent ) . toMatch (
207
212
/ 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 \) / ,
208
213
) ;
209
214
} ) ;
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
+ } ) ;
210
252
} ) ;
211
253
} ) ;
0 commit comments