2016-07-18 06:50:31 -04:00
|
|
|
/**
|
|
|
|
* @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';
|
2017-03-02 12:37:01 -05:00
|
|
|
import {ɵstringify as stringify} from '@angular/core';
|
2016-09-12 22:14:17 -04:00
|
|
|
import {NgModule} from '@angular/core/src/metadata';
|
2017-08-16 12:00:03 -04:00
|
|
|
import {JitReflector} from '@angular/platform-browser-dynamic/src/compiler_reflector';
|
2016-07-18 06:50:31 -04:00
|
|
|
|
|
|
|
class SomeClass1 {}
|
|
|
|
class SomeClass2 {}
|
|
|
|
class SomeClass3 {}
|
|
|
|
class SomeClass4 {}
|
|
|
|
class SomeClass5 {}
|
|
|
|
|
|
|
|
@NgModule({
|
|
|
|
declarations: [SomeClass1],
|
|
|
|
imports: [SomeClass2],
|
|
|
|
exports: [SomeClass3],
|
|
|
|
providers: [SomeClass4],
|
2016-07-25 03:36:30 -04:00
|
|
|
entryComponents: [SomeClass5]
|
2016-07-18 06:50:31 -04:00
|
|
|
})
|
|
|
|
class SomeModule {
|
|
|
|
}
|
|
|
|
|
|
|
|
class SimpleClass {}
|
|
|
|
|
|
|
|
export function main() {
|
|
|
|
describe('NgModuleResolver', () => {
|
2016-11-12 08:08:58 -05:00
|
|
|
let resolver: NgModuleResolver;
|
2016-07-18 06:50:31 -04:00
|
|
|
|
2017-05-18 16:46:51 -04:00
|
|
|
beforeEach(() => { resolver = new NgModuleResolver(new JitReflector()); });
|
2016-07-18 06:50:31 -04:00
|
|
|
|
|
|
|
it('should read out the metadata from the class', () => {
|
2016-11-12 08:08:58 -05:00
|
|
|
const moduleMetadata = resolver.resolve(SomeModule);
|
2016-09-12 22:14:17 -04:00
|
|
|
expect(moduleMetadata).toEqual(new NgModule({
|
2016-07-18 06:50:31 -04:00
|
|
|
declarations: [SomeClass1],
|
|
|
|
imports: [SomeClass2],
|
|
|
|
exports: [SomeClass3],
|
|
|
|
providers: [SomeClass4],
|
2016-07-25 03:36:30 -04:00
|
|
|
entryComponents: [SomeClass5]
|
2016-07-18 06:50:31 -04:00
|
|
|
}));
|
|
|
|
});
|
|
|
|
|
2016-11-18 18:17:44 -05:00
|
|
|
it('should throw when simple class has no NgModule decorator', () => {
|
2016-07-18 06:50:31 -04:00
|
|
|
expect(() => resolver.resolve(SimpleClass))
|
|
|
|
.toThrowError(`No NgModule metadata found for '${stringify(SimpleClass)}'.`);
|
|
|
|
});
|
2016-11-18 18:17:44 -05:00
|
|
|
|
|
|
|
it('should support inheriting the metadata', function() {
|
|
|
|
@NgModule({id: 'p'})
|
|
|
|
class Parent {
|
|
|
|
}
|
|
|
|
|
|
|
|
class ChildNoDecorator extends Parent {}
|
|
|
|
|
|
|
|
@NgModule({id: 'c'})
|
|
|
|
class ChildWithDecorator extends Parent {
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(resolver.resolve(ChildNoDecorator)).toEqual(new NgModule({id: 'p'}));
|
|
|
|
|
|
|
|
expect(resolver.resolve(ChildWithDecorator)).toEqual(new NgModule({id: 'c'}));
|
|
|
|
});
|
|
|
|
|
2016-07-18 06:50:31 -04:00
|
|
|
});
|
|
|
|
}
|