Skip to content

Commit

Permalink
fix: respecting internals vs externals
Browse files Browse the repository at this point in the history
BREAKING CHANGE: respects internals vs externals, to access them use guts or MockBuilder

closes #44
  • Loading branch information
satanTime committed Nov 13, 2020
1 parent 9795203 commit badf48d
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/common/ng-mocks-universe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const ngMocksUniverse = {
cacheMocks: new Map(),
cacheProviders: new Map(),
config: new Map(),
flags: new Set<string>(['cacheModule', 'cacheComponent', 'cacheDirective', 'cacheProvider']),
flags: new Set<string>(['cacheModule', 'cacheComponent', 'cacheDirective', 'cacheProvider', 'correctModuleExports']),
global: new Map(),
touches: new Set<AnyType<any> | InjectionToken<any>>(),
};
8 changes: 7 additions & 1 deletion lib/mock-helper/mock-helper.reset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
3 changes: 3 additions & 0 deletions lib/mock-module/mock-module.spec.fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export class ExampleConsumerComponent {}
export class ChildModule {}

@NgModule({
exports: [ChildModule],
imports: [ChildModule],
})
export class ParentModule {}
Expand All @@ -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 {}
Expand Down
56 changes: 56 additions & 0 deletions tests/correct-module-exports-11/test.spec.ts
Original file line number Diff line number Diff line change
@@ -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('<external></external>');
});
});

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('<internal></internal>');
});
});

describe('correct-module-exports-11:builder', () => {
beforeEach(() => MockBuilder(null, TargetModule));

it('renders an internal module', () => {
const fixture = MockRender(InternalComponent);
expect(fixture.nativeElement.innerHTML).toEqual('<internal></internal>');
});
});
1 change: 1 addition & 0 deletions tests/issue-222/common-module.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class TargetComponent {}

@NgModule({
declarations: [TargetComponent],
exports: [TargetComponent],
imports: [CommonModule],
})
class TargetModule {}
Expand Down

0 comments on commit badf48d

Please sign in to comment.