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 export things use MockBuilder

closes #44
  • Loading branch information
satanTime committed Nov 13, 2020
1 parent 9795203 commit ef630dc
Show file tree
Hide file tree
Showing 5 changed files with 50 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
38 changes: 38 additions & 0 deletions tests/correct-module-exports-11/test.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Component, NgModule } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { MockModule, MockRender } 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', () => {
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>');
});
});
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 ef630dc

Please sign in to comment.