Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit 547dc65

Browse files
jgw96danbucholtz
authored andcommitted
test(generators): improve failure path tests (#861)
1 parent 58c0659 commit 547dc65

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

src/generators/util.spec.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ $TAB_CONTENT
410410
const suppliedName = 'settings view';
411411

412412
it('should return a succesful promise', () => {
413+
// set up spies
413414
spyOn(helpers, helpers.readFileAsync.name).and.returnValue(Promise.resolve('file content'));
414415
spyOn(fs, 'readdirSync').and.returnValue([
415416
join(process.cwd(), 'path', 'to', 'nowhere'),
@@ -419,22 +420,18 @@ $TAB_CONTENT
419420
spyOn(TypeScriptUtils, TypeScriptUtils.insertNamedImportIfNeeded.name).and.returnValue('file content');
420421
spyOn(TypeScriptUtils, TypeScriptUtils.appendNgModuleDeclaration.name).and.returnValue('sliced string');
421422

423+
// what we want to test
422424
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 }]);
423425

426+
// test
424427
return promise.then(() => {
425428
expect(helpers.readFileAsync).toHaveBeenCalled();
426429
expect(helpers.writeFileAsync).toHaveBeenCalled();
427430
});
428431
});
429432

430433
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'`;
438435
spyOn(helpers, helpers.writeFileAsync.name).and.returnValue(Promise.reject(new Error(knownErrorMsg)));
439436

440437
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
443440
}).catch((err: Error) => {
444441
expect(err.message).toEqual(knownErrorMsg);
445442
});
446-
*/
447443
});
448444

449445
});
@@ -486,22 +482,15 @@ $TAB_CONTENT
486482
});
487483

488484
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'`;
497486
spyOn(helpers, helpers.writeFileAsync.name).and.returnValue(Promise.reject(new Error(knownErrorMsg)));
487+
498488
const promise = util.nonPageFileManipulation(context, 'coolStuff', join('src', 'pages', 'cool-tab-one', 'cool-tab-one.module.ts'), 'pipe');
499489
return promise.then(() => {
500490
throw new Error('should never happen');
501491
}).catch((err: Error) => {
502492
expect(err.message).toEqual(knownErrorMsg);
503493
});
504-
*/
505494
});
506495
});
507496
});

0 commit comments

Comments
 (0)