@@ -5,6 +5,7 @@ import * as helpers from '../util/helpers';
5
5
import * as globUtils from '../util/glob-util' ;
6
6
import * as util from './util' ;
7
7
import * as GeneratorConstants from './constants' ;
8
+ import * as TypeScriptUtils from '../util/typescript-utils' ;
8
9
9
10
describe ( 'util' , ( ) => {
10
11
describe ( 'hydrateRequest' , ( ) => {
@@ -406,13 +407,26 @@ $TAB_CONTENT
406
407
} ) ;
407
408
408
409
it ( 'should return a succesful promise' , ( ) => {
409
- let rejected = false ;
410
+ // set up spies
411
+ spyOn ( helpers , helpers . readFileAsync . name ) . and . returnValue ( Promise . resolve ( 'file content' ) ) ;
412
+ spyOn ( fs , 'readdirSync' ) . and . returnValue ( [
413
+ '/path/to/nowhere' ,
414
+ 'path/to/somewhere'
415
+ ] ) ;
416
+ spyOn ( helpers , helpers . writeFileAsync . name ) . and . returnValue ( Promise . resolve ( ) ) ;
417
+ spyOn ( helpers , helpers . mkDirpAsync . name ) . and . returnValue ( Promise . resolve ( ) ) ;
418
+ spyOn ( TypeScriptUtils , TypeScriptUtils . insertNamedImportIfNeeded . name ) . and . returnValue ( 'file content' ) ;
419
+ spyOn ( TypeScriptUtils , TypeScriptUtils . appendNgModuleDeclaration . name ) . and . returnValue ( 'sliced string' ) ;
410
420
411
- util . nonPageFileManipulation ( context , 'coolStuff' , '/src/pages/cool-tab-one/cool-tab-one.module.ts' , 'pipe' ) . catch ( ( ) => {
412
- rejected = true ;
413
- } ) ;
421
+ // what we want to test
422
+ const promise = util . nonPageFileManipulation ( context , 'coolStuff' , '/src/pages/cool-tab-one/cool-tab-one.module.ts' , 'pipe' ) ;
414
423
415
- expect ( rejected ) . toBeFalsy ( ) ;
424
+ // test
425
+ return promise . then ( ( value : string [ ] ) => {
426
+ expect ( helpers . readFileAsync ) . toHaveBeenCalled ( ) ;
427
+ expect ( helpers . writeFileAsync ) . toHaveBeenCalled ( ) ;
428
+ expect ( helpers . mkDirpAsync ) . toHaveBeenCalled ( ) ;
429
+ } ) ;
416
430
} ) ;
417
431
418
432
it ( 'should throw when files are not written succesfully' , ( ) => {
0 commit comments