Skip to content

Commit

Permalink
fix: module exports is now all declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
ike18t committed Feb 2, 2018
1 parent 610cbdc commit fbb0e73
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions lib/mock-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,27 @@ const mockProvider = (provider: any) => ({
provide: provider, useValue: {}
});

class MockedModule {}

export function MockModule<TModule>(module: Type<TModule>): any {
return NgModule(MockIt(module))(MockedModule);
return NgModule(MockIt(module))(class MockedModule {});
}

function MockIt(module: any): any {
const mockedModule = { declarations: [] as any[],
exports: [] as any[],
providers: [] as any[] };
const declarations = (module as any).__annotations__[0].declarations || [];
const exports = (module as any).__annotations__[0].exports || [];
const imports = (module as any).__annotations__[0].imports || [];
const providers = (module as any).__annotations__[0].providers || [];
mockedModule.declarations = [...declarations.map(mockDeclaration)];
mockedModule.exports = exports;

mockedModule.exports = mockedModule.declarations = [...declarations.map(mockDeclaration)];
mockedModule.providers = providers.map(mockProvider);
imports.reduce((acc: any, im: any) => {
const result = MockIt(im);

imports.reduce((acc: any, imPort: any) => {
const result = MockIt(imPort);
acc.declarations.push(...result.declarations);
acc.providers.push(...result.providers);
acc.exports.push(...result.declarations);
}, mockedModule);

return mockedModule;
}

0 comments on commit fbb0e73

Please sign in to comment.