diff --git a/lib/common/ng-mocks-universe.ts b/lib/common/ng-mocks-universe.ts index 749b03db56..67860e2bcb 100644 --- a/lib/common/ng-mocks-universe.ts +++ b/lib/common/ng-mocks-universe.ts @@ -12,7 +12,7 @@ export const ngMocksUniverse = { cacheMocks: new Map(), cacheProviders: new Map(), config: new Map(), - flags: new Set(['cacheModule', 'cacheComponent', 'cacheDirective', 'cacheProvider']), + flags: new Set(['cacheModule', 'cacheComponent', 'cacheDirective', 'cacheProvider', 'correctModuleExports']), global: new Map(), touches: new Set | InjectionToken>(), }; diff --git a/lib/mock-helper/mock-helper.reset.ts b/lib/mock-helper/mock-helper.reset.ts index bac0ae7532..ef8529b830 100644 --- a/lib/mock-helper/mock-helper.reset.ts +++ b/lib/mock-helper/mock-helper.reset.ts @@ -6,6 +6,12 @@ export default (): void => { ngMocksUniverse.cacheProviders = new Map(); ngMocksUniverse.config = new Map(); ngMocksUniverse.global = new Map(); - ngMocksUniverse.flags = new Set(['cacheModule', 'cacheComponent', 'cacheDirective', 'cacheProvider']); + ngMocksUniverse.flags = new Set([ + 'cacheModule', + 'cacheComponent', + 'cacheDirective', + 'cacheProvider', + 'correctModuleExports', + ]); ngMocksUniverse.touches = new Set(); }; diff --git a/lib/mock-module/mock-module.spec.fixtures.ts b/lib/mock-module/mock-module.spec.fixtures.ts index 514c89a513..6d5f39dc66 100644 --- a/lib/mock-module/mock-module.spec.fixtures.ts +++ b/lib/mock-module/mock-module.spec.fixtures.ts @@ -54,6 +54,7 @@ export class ExampleConsumerComponent {} export class ChildModule {} @NgModule({ + exports: [ChildModule], imports: [ChildModule], }) export class ParentModule {} @@ -69,11 +70,13 @@ export class SameImports1Module {} export class SameImports2Module {} @NgModule({ + exports: [ChildModule], imports: [ChildModule], }) export class LogicNestedModule {} @NgModule({ + exports: [ChildModule, LogicNestedModule], imports: [ChildModule, LogicNestedModule], }) export class LogicRootModule {} diff --git a/tests/correct-module-exports-11/test.spec.ts b/tests/correct-module-exports-11/test.spec.ts new file mode 100644 index 0000000000..662d5f2684 --- /dev/null +++ b/tests/correct-module-exports-11/test.spec.ts @@ -0,0 +1,56 @@ +import { Component, NgModule } from '@angular/core'; +import { TestBed } from '@angular/core/testing'; +import { MockBuilder, MockModule, MockRender, ngMocks } from 'ng-mocks'; + +@Component({ + selector: 'internal', + template: 'internal', +}) +class InternalComponent {} + +@Component({ + selector: 'external', + template: 'external', +}) +class ExternalComponent {} + +@NgModule({ + declarations: [InternalComponent, ExternalComponent], + exports: [ExternalComponent], +}) +class TargetModule {} + +describe('correct-module-exports-11:proper', () => { + beforeEach(() => + TestBed.configureTestingModule({ + imports: [MockModule(TargetModule)], + }).compileComponents() + ); + + it('fails on not exported module', () => { + expect(() => MockRender(InternalComponent)).toThrowError(/'internal' is not a known element/); + }); + + it('renders an exported module', () => { + const fixture = MockRender(ExternalComponent); + expect(fixture.nativeElement.innerHTML).toEqual(''); + }); +}); + +describe('correct-module-exports-11:guts', () => { + beforeEach(() => TestBed.configureTestingModule(ngMocks.guts(null, TargetModule)).compileComponents()); + + it('renders an internal module', () => { + const fixture = MockRender(InternalComponent); + expect(fixture.nativeElement.innerHTML).toEqual(''); + }); +}); + +describe('correct-module-exports-11:builder', () => { + beforeEach(() => MockBuilder(null, TargetModule)); + + it('renders an internal module', () => { + const fixture = MockRender(InternalComponent); + expect(fixture.nativeElement.innerHTML).toEqual(''); + }); +}); diff --git a/tests/issue-222/common-module.spec.ts b/tests/issue-222/common-module.spec.ts index 1a2e55bec9..017adf4a89 100644 --- a/tests/issue-222/common-module.spec.ts +++ b/tests/issue-222/common-module.spec.ts @@ -11,6 +11,7 @@ class TargetComponent {} @NgModule({ declarations: [TargetComponent], + exports: [TargetComponent], imports: [CommonModule], }) class TargetModule {}