refactor(core): change module semantics
This contains major changes to the compiler, bootstrap of the platforms and test environment initialization. Main part of #10043 Closes #10164 BREAKING CHANGE: - Semantics and name of `@AppModule` (now `@NgModule`) changed quite a bit. This is actually not breaking as `@AppModules` were not part of rc.4. We will have detailed docs on `@NgModule` separately. - `coreLoadAndBootstrap` and `coreBootstrap` can't be used any more (without migration support). Use `bootstrapModule` / `bootstrapModuleFactory` instead. - All Components listed in routes have to be part of the `declarations` of an NgModule. Either directly on the bootstrap module / lazy loaded module, or in an NgModule imported by them.
This commit is contained in:
53
modules/@angular/compiler/test/ng_module_resolver_spec.ts
Normal file
53
modules/@angular/compiler/test/ng_module_resolver_spec.ts
Normal file
@ -0,0 +1,53 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {NgModuleResolver} from '@angular/compiler/src/ng_module_resolver';
|
||||
import {NgModule, NgModuleMetadata} from '@angular/core/src/metadata';
|
||||
import {stringify} from '../src/facade/lang';
|
||||
|
||||
class SomeClass1 {}
|
||||
class SomeClass2 {}
|
||||
class SomeClass3 {}
|
||||
class SomeClass4 {}
|
||||
class SomeClass5 {}
|
||||
|
||||
@NgModule({
|
||||
declarations: [SomeClass1],
|
||||
imports: [SomeClass2],
|
||||
exports: [SomeClass3],
|
||||
providers: [SomeClass4],
|
||||
precompile: [SomeClass5]
|
||||
})
|
||||
class SomeModule {
|
||||
}
|
||||
|
||||
class SimpleClass {}
|
||||
|
||||
export function main() {
|
||||
describe('NgModuleResolver', () => {
|
||||
var resolver: NgModuleResolver;
|
||||
|
||||
beforeEach(() => { resolver = new NgModuleResolver(); });
|
||||
|
||||
it('should read out the metadata from the class', () => {
|
||||
var viewMetadata = resolver.resolve(SomeModule);
|
||||
expect(viewMetadata).toEqual(new NgModuleMetadata({
|
||||
declarations: [SomeClass1],
|
||||
imports: [SomeClass2],
|
||||
exports: [SomeClass3],
|
||||
providers: [SomeClass4],
|
||||
precompile: [SomeClass5]
|
||||
}));
|
||||
});
|
||||
|
||||
it('should throw when simple class has no component decorator', () => {
|
||||
expect(() => resolver.resolve(SimpleClass))
|
||||
.toThrowError(`No NgModule metadata found for '${stringify(SimpleClass)}'.`);
|
||||
});
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user