2016-06-23 12:47:54 -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
|
|
|
|
*/
|
|
|
|
|
2016-04-28 20:50:03 -04:00
|
|
|
import {ViewResolver} from '@angular/compiler/src/view_resolver';
|
|
|
|
import {Component, ViewMetadata} from '@angular/core/src/metadata';
|
2015-10-06 20:03:37 -04:00
|
|
|
|
|
|
|
class SomeDir {}
|
|
|
|
class SomePipe {}
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'sample',
|
2016-06-08 19:38:52 -04:00
|
|
|
template: 'some template',
|
2015-10-06 20:03:37 -04:00
|
|
|
directives: [SomeDir],
|
|
|
|
pipes: [SomePipe],
|
2016-06-08 19:38:52 -04:00
|
|
|
styles: ['some styles']
|
2015-10-06 20:03:37 -04:00
|
|
|
})
|
|
|
|
class ComponentWithTemplate {
|
|
|
|
}
|
|
|
|
|
2015-10-06 22:14:45 -04:00
|
|
|
@Component({selector: 'sample'})
|
|
|
|
class ComponentWithoutView {
|
|
|
|
}
|
|
|
|
|
2015-10-06 20:03:37 -04:00
|
|
|
|
|
|
|
class SimpleClass {}
|
|
|
|
|
|
|
|
export function main() {
|
2016-06-08 19:38:52 -04:00
|
|
|
describe('ViewResolver', () => {
|
2016-02-19 14:49:31 -05:00
|
|
|
var resolver: ViewResolver;
|
2015-10-06 20:03:37 -04:00
|
|
|
|
|
|
|
beforeEach(() => { resolver = new ViewResolver(); });
|
|
|
|
|
|
|
|
it('should read out the View metadata from the Component metadata', () => {
|
|
|
|
var viewMetadata = resolver.resolve(ComponentWithTemplate);
|
2016-06-08 19:38:52 -04:00
|
|
|
expect(viewMetadata).toEqual(new ViewMetadata({
|
|
|
|
template: 'some template',
|
|
|
|
directives: [SomeDir],
|
|
|
|
pipes: [SomePipe],
|
|
|
|
styles: ['some styles']
|
|
|
|
}));
|
2015-10-06 20:03:37 -04:00
|
|
|
});
|
|
|
|
|
2016-06-04 22:46:55 -04:00
|
|
|
it('should throw when Component has neither template nor templateUrl set', () => {
|
2015-10-06 20:03:37 -04:00
|
|
|
expect(() => resolver.resolve(ComponentWithoutView))
|
2016-06-22 17:58:57 -04:00
|
|
|
.toThrowError(
|
|
|
|
/Component 'ComponentWithoutView' must have either 'template' or 'templateUrl' set/);
|
2015-10-06 20:03:37 -04:00
|
|
|
});
|
|
|
|
|
2016-06-04 22:46:55 -04:00
|
|
|
it('should throw when simple class has no component decorator', () => {
|
2015-10-06 20:03:37 -04:00
|
|
|
expect(() => resolver.resolve(SimpleClass))
|
2016-06-22 17:58:57 -04:00
|
|
|
.toThrowError('Could not compile \'SimpleClass\' because it is not a component.');
|
2015-10-06 20:03:37 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|