Files
angular-docs-cn/modules/@angular/compiler/test/view_resolver_spec.ts
T

53 lines
1.5 KiB
TypeScript
Raw Normal View History

import {ViewResolver} from '@angular/compiler/src/view_resolver';
import {Component, ViewMetadata} from '@angular/core/src/metadata';
2016-06-08 16:38:52 -07:00
import {beforeEach, ddescribe, describe, expect, iit, it} from '@angular/core/testing';
class SomeDir {}
class SomePipe {}
@Component({
selector: 'sample',
2016-06-08 16:38:52 -07:00
template: 'some template',
directives: [SomeDir],
pipes: [SomePipe],
2016-06-08 16:38:52 -07:00
styles: ['some styles']
})
class ComponentWithTemplate {
}
2015-10-06 19:14:45 -07:00
@Component({selector: 'sample'})
class ComponentWithoutView {
}
class SimpleClass {}
export function main() {
2016-06-08 16:38:52 -07:00
describe('ViewResolver', () => {
2016-02-19 11:49:31 -08:00
var resolver: ViewResolver;
beforeEach(() => { resolver = new ViewResolver(); });
it('should read out the View metadata from the Component metadata', () => {
var viewMetadata = resolver.resolve(ComponentWithTemplate);
2016-06-08 16:38:52 -07:00
expect(viewMetadata).toEqual(new ViewMetadata({
template: 'some template',
directives: [SomeDir],
pipes: [SomePipe],
styles: ['some styles']
}));
});
it('should throw when Component has neither template nor templateUrl set', () => {
expect(() => resolver.resolve(ComponentWithoutView))
.toThrowErrorWith(
2016-06-08 16:38:52 -07:00
'Component \'ComponentWithoutView\' must have either \'template\' or \'templateUrl\' set');
});
it('should throw when simple class has no component decorator', () => {
expect(() => resolver.resolve(SimpleClass))
2016-06-08 16:38:52 -07:00
.toThrowErrorWith('Could not compile \'SimpleClass\' because it is not a component.');
});
});
}