@@ -262,5 +262,111 @@ export class AppModule {}
262
262
const result = tsUtils . appendNgModuleDeclaration ( knownPath , knownContent , 'CoolComponent' ) ;
263
263
expect ( result ) . toEqual ( expectedContent ) ;
264
264
} ) ;
265
+
266
+ it ( 'should return a modified file content for providers' , ( ) => {
267
+ const knownContent = `
268
+ import { NgModule } from '@angular/core';
269
+ import { BrowserModule } from '@angular/platform-browser';
270
+ import { IonicApp, IonicModule } from '../../../../..';
271
+
272
+ import { AppComponent } from './app.component';
273
+ import { RootPageModule } from '../pages/root-page/root-page.module';
274
+
275
+ @NgModule({
276
+ declarations: [
277
+ AppComponent
278
+ ],
279
+ imports: [
280
+ BrowserModule,
281
+ IonicModule.forRoot(AppComponent),
282
+ RootPageModule
283
+ ],
284
+ bootstrap: [IonicApp],
285
+ providers: []
286
+ })
287
+ export class AppModule {}
288
+ ` ;
289
+
290
+ const knownPath = '/some/fake/path' ;
291
+
292
+ const expectedContent = `
293
+ import { NgModule } from \'@angular/core\';
294
+ import { BrowserModule } from \'@angular/platform-browser\';
295
+ import { IonicApp, IonicModule } from \'../../../../..\';
296
+
297
+ import { AppComponent } from \'./app.component\';
298
+ import { RootPageModule } from \'../pages/root-page/root-page.module\';
299
+
300
+ @NgModule({
301
+ declarations: [
302
+ AppComponent
303
+ ],
304
+ imports: [
305
+ BrowserModule,
306
+ IonicModule.forRoot(AppComponent),
307
+ RootPageModule
308
+ ],
309
+ bootstrap: [IonicApp],
310
+ providers: [CoolProvider]
311
+ })
312
+ export class AppModule {}
313
+ ` ;
314
+
315
+ const result = tsUtils . appendNgModuleDeclaration ( knownPath , knownContent , 'CoolProvider' , 'provider' ) ;
316
+ expect ( result ) . toEqual ( expectedContent ) ;
317
+ } ) ;
318
+
319
+ it ( 'should return a modified file content for providers that already has one provider' , ( ) => {
320
+ const knownContent = `
321
+ import { NgModule } from '@angular/core';
322
+ import { BrowserModule } from '@angular/platform-browser';
323
+ import { IonicApp, IonicModule } from '../../../../..';
324
+
325
+ import { AppComponent } from './app.component';
326
+ import { RootPageModule } from '../pages/root-page/root-page.module';
327
+
328
+ @NgModule({
329
+ declarations: [
330
+ AppComponent
331
+ ],
332
+ imports: [
333
+ BrowserModule,
334
+ IonicModule.forRoot(AppComponent),
335
+ RootPageModule
336
+ ],
337
+ bootstrap: [IonicApp],
338
+ providers: [AwesomeProvider]
339
+ })
340
+ export class AppModule {}
341
+ ` ;
342
+
343
+ const knownPath = '/some/fake/path' ;
344
+
345
+ const expectedContent = `
346
+ import { NgModule } from '@angular/core';
347
+ import { BrowserModule } from '@angular/platform-browser';
348
+ import { IonicApp, IonicModule } from '../../../../..';
349
+
350
+ import { AppComponent } from './app.component';
351
+ import { RootPageModule } from '../pages/root-page/root-page.module';
352
+
353
+ @NgModule({
354
+ declarations: [
355
+ AppComponent
356
+ ],
357
+ imports: [
358
+ BrowserModule,
359
+ IonicModule.forRoot(AppComponent),
360
+ RootPageModule
361
+ ],
362
+ bootstrap: [IonicApp],
363
+ providers: [AwesomeProvider, CoolProvider]
364
+ })
365
+ export class AppModule {}
366
+ ` ;
367
+
368
+ const result = tsUtils . appendNgModuleDeclaration ( knownPath , knownContent , 'CoolProvider' , 'provider' ) ;
369
+ expect ( result ) . toEqual ( expectedContent ) ;
370
+ } ) ;
265
371
} ) ;
266
372
0 commit comments