Skip to content

Commit

Permalink
feat(51): Add mocked entry components to mocked modules
Browse files Browse the repository at this point in the history
Fixes: #51
  • Loading branch information
ike18t committed May 14, 2019
1 parent b7f6a84 commit a321b14
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions examples/MockModule/dependency.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { DependencyComponent } from './dependency.component';
declarations: [
DependencyComponent
],
entryComponents: [
DependencyComponent
],
imports: [
CommonModule,
],
Expand Down
7 changes: 6 additions & 1 deletion lib/mock-module/mock-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type ImportInstance = Type<NgModule> | ModuleWithProviders;

interface IModuleOptions {
declarations?: Array<Type<any>>;
entryComponents?: Array<Type<any>>;
exports?: Array<Type<any>>;
imports?: Array<Type<any> | ModuleWithProviders | any[]>;
providers?: Provider[];
Expand Down Expand Up @@ -122,7 +123,7 @@ const NEVER_MOCK: Array<Type<NgModule>> = [CommonModule];

function MockIt(module: Type<NgModule>): IModuleOptions {
const mockedModule: IModuleOptions = {};
const {declarations = [], imports = [], providers = []} = ngModuleResolver.resolve(module);
const { declarations = [], entryComponents = [], imports = [], providers = [] } = ngModuleResolver.resolve(module);

if (imports.length) {
mockedModule.imports = flatten(imports).map((instance: Type<any>) => {
Expand All @@ -140,6 +141,10 @@ function MockIt(module: Type<NgModule>): IModuleOptions {
mockedModule.declarations = flatten(declarations).map(MockDeclaration);
}

if (entryComponents.length) {
mockedModule.entryComponents = flatten(entryComponents).map(MockDeclaration);
}

if (providers.length) {
mockedModule.providers = flatten(providers).map(mockProvider)
.filter((provider) => !!provider) as Provider[];
Expand Down

0 comments on commit a321b14

Please sign in to comment.