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

Commit aac2a38

Browse files
committed
chore(tests): test getNgModules
1 parent b680eb8 commit aac2a38

File tree

1 file changed

+42
-7
lines changed

1 file changed

+42
-7
lines changed

src/generators/util.spec.ts

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { basename, join } from 'path';
22
import * as fs from 'fs';
33
import * as Constants from '../util/constants';
44
import * as helpers from '../util/helpers';
5+
import * as globUtils from '../util/glob-util';
6+
import { GlobResult } from '../util/glob-util';
57
import * as util from './util';
68
import * as GeneratorConstants from './constants';
79

@@ -299,13 +301,7 @@ export class $CLASSNAMEModule {}
299301
const providersDir = '/path/to/providers';
300302

301303
beforeEach(() => {
302-
context = {
303-
componentsDir,
304-
directivesDir,
305-
pagesDir,
306-
pipesDir,
307-
providersDir,
308-
};
304+
context = { componentsDir, directivesDir, pagesDir, pipesDir, providersDir };
309305
});
310306

311307
it('should return the appropriate components directory', () => {
@@ -332,4 +328,43 @@ export class $CLASSNAMEModule {}
332328
expect(() => util.getDirToWriteToByType(context, 'dan')).toThrowError('Unknown Generator Type: dan');
333329
});
334330
});
331+
332+
describe('getNgModules', () => {
333+
let context: any;
334+
const componentsDir = '/path/to/components';
335+
const directivesDir = '/path/to/directives';
336+
const pagesDir = '/path/to/pages';
337+
const pipesDir = '/path/to/pipes';
338+
const providersDir = '/path/to/providers';
339+
340+
beforeEach(() => {
341+
context = { componentsDir, directivesDir, pagesDir, pipesDir, providersDir };
342+
});
343+
344+
function genMockGlobResults(types: string[]): GlobResult[] {
345+
return types.map((type) => {
346+
return { absolutePath: `/path/to/${type}`, base: '/path' }
347+
});
348+
}
349+
350+
it('should return an empty list of glob results', () => {
351+
const globAllSpy = spyOn(globUtils, globUtils.globAll.name);
352+
util.getNgModules(context, []);
353+
expect(globAllSpy).toHaveBeenCalledWith([]);
354+
});
355+
356+
it('should return a list of glob results for components', () => {
357+
const globAllSpy = spyOn(globUtils, globUtils.globAll.name);
358+
spyOn(helpers, helpers.getStringPropertyValue.name).and.returnValue('.module.ts');
359+
util.getNgModules(context, ['component']);
360+
expect(globAllSpy).toHaveBeenCalledWith(['/path/to/components/**/*.module.ts']);
361+
});
362+
363+
it('should return a list of glob results for pages and components', () => {
364+
const globAllSpy = spyOn(globUtils, globUtils.globAll.name);
365+
spyOn(helpers, helpers.getStringPropertyValue.name).and.returnValue('.module.ts');
366+
util.getNgModules(context, ['page', 'component']);
367+
expect(globAllSpy).toHaveBeenCalledWith(['/path/to/pages/**/*.module.ts', '/path/to/components/**/*.module.ts']);
368+
});
369+
});
335370
});

0 commit comments

Comments
 (0)