@@ -410,6 +410,7 @@ $TAB_CONTENT
410
410
const suppliedName = 'settings view' ;
411
411
412
412
it ( 'should return a succesful promise' , ( ) => {
413
+ // set up spies
413
414
spyOn ( helpers , helpers . readFileAsync . name ) . and . returnValue ( Promise . resolve ( 'file content' ) ) ;
414
415
spyOn ( fs , 'readdirSync' ) . and . returnValue ( [
415
416
join ( process . cwd ( ) , 'path' , 'to' , 'nowhere' ) ,
@@ -419,22 +420,18 @@ $TAB_CONTENT
419
420
spyOn ( TypeScriptUtils , TypeScriptUtils . insertNamedImportIfNeeded . name ) . and . returnValue ( 'file content' ) ;
420
421
spyOn ( TypeScriptUtils , TypeScriptUtils . appendNgModuleDeclaration . name ) . and . returnValue ( 'sliced string' ) ;
421
422
423
+ // what we want to test
422
424
const promise = util . tabsModuleManipulation ( [ [ '/src/pages/cool-tab-one/cool-tab-one.module.ts' ] ] , { name : suppliedName , className : className , fileName : fileName } , [ { name : suppliedName , className : className , fileName : fileName } ] ) ;
423
425
426
+ // test
424
427
return promise . then ( ( ) => {
425
428
expect ( helpers . readFileAsync ) . toHaveBeenCalled ( ) ;
426
429
expect ( helpers . writeFileAsync ) . toHaveBeenCalled ( ) ;
427
430
} ) ;
428
431
} ) ;
429
432
430
433
it ( 'should throw when files are not written succesfully' , ( ) => {
431
- /*spyOn(helpers, helpers.writeFileAsync.name).and.throwError;
432
-
433
- expect(util.tabsModuleManipulation([['/src/pages/cool-tab-one/cool-tab-one.module.ts']], { name: suppliedName, className: className, fileName: fileName }, [{ name: suppliedName, className: className, fileName: fileName }])).toThrow();
434
- */
435
- // This test is not working correctly, it should look more like this below
436
- /*
437
- const knownErrorMsg = 'some known error';
434
+ const knownErrorMsg = `ENOENT: no such file or directory, open 'undefined/settings-view.module.ts'` ;
438
435
spyOn ( helpers , helpers . writeFileAsync . name ) . and . returnValue ( Promise . reject ( new Error ( knownErrorMsg ) ) ) ;
439
436
440
437
const promise = util . tabsModuleManipulation ( [ [ '/src/pages/cool-tab-one/cool-tab-one.module.ts' ] ] , { name : suppliedName , className : className , fileName : fileName } , [ { name : suppliedName , className : className , fileName : fileName } ] ) ;
@@ -443,7 +440,6 @@ $TAB_CONTENT
443
440
} ) . catch ( ( err : Error ) => {
444
441
expect ( err . message ) . toEqual ( knownErrorMsg ) ;
445
442
} ) ;
446
- */
447
443
} ) ;
448
444
449
445
} ) ;
@@ -486,22 +482,15 @@ $TAB_CONTENT
486
482
} ) ;
487
483
488
484
it ( 'should throw when files are not written succesfully' , ( ) => {
489
- /*spyOn(helpers, helpers.writeFileAsync.name).and.throwError;
490
-
491
- expect().toThrow();
492
- */
493
- // This above test is likely not working correctly
494
- // it should look more like this
495
- /*
496
- const knownErrorMsg = 'some error';
485
+ const knownErrorMsg = `ENOENT: no such file or directory, open 'src/pages/cool-tab-one/cool-tab-one.module.ts'` ;
497
486
spyOn ( helpers , helpers . writeFileAsync . name ) . and . returnValue ( Promise . reject ( new Error ( knownErrorMsg ) ) ) ;
487
+
498
488
const promise = util . nonPageFileManipulation ( context , 'coolStuff' , join ( 'src' , 'pages' , 'cool-tab-one' , 'cool-tab-one.module.ts' ) , 'pipe' ) ;
499
489
return promise . then ( ( ) => {
500
490
throw new Error ( 'should never happen' ) ;
501
491
} ) . catch ( ( err : Error ) => {
502
492
expect ( err . message ) . toEqual ( knownErrorMsg ) ;
503
493
} ) ;
504
- */
505
494
} ) ;
506
495
} ) ;
507
496
} ) ;
0 commit comments