2015-10-13 03:29:13 -04:00
|
|
|
import {ddescribe, describe, it, iit, expect, beforeEach} from 'angular2/testing_internal';
|
2016-01-06 17:13:44 -05:00
|
|
|
import {ViewResolver} from 'angular2/src/compiler/view_resolver';
|
2016-03-08 16:36:48 -05:00
|
|
|
import {Component, ViewMetadata} from 'angular2/src/core/metadata';
|
2015-10-06 20:03:37 -04:00
|
|
|
|
|
|
|
class SomeDir {}
|
|
|
|
class SomePipe {}
|
|
|
|
|
2016-03-08 16:36:48 -05:00
|
|
|
@Component({
|
|
|
|
selector: 'sample',
|
2016-04-12 12:40:37 -04:00
|
|
|
template: "some template",
|
2016-03-08 16:36:48 -05:00
|
|
|
directives: [SomeDir],
|
|
|
|
pipes: [SomePipe],
|
2016-04-12 12:40:37 -04:00
|
|
|
styles: ["some styles"]
|
2016-03-08 16:36:48 -05:00
|
|
|
})
|
2015-10-06 20:03:37 -04:00
|
|
|
class ComponentWithView {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'sample',
|
2016-04-12 12:40:37 -04:00
|
|
|
template: "some template",
|
2015-10-06 20:03:37 -04:00
|
|
|
directives: [SomeDir],
|
|
|
|
pipes: [SomePipe],
|
2016-04-12 12:40:37 -04:00
|
|
|
styles: ["some styles"]
|
2015-10-06 20:03:37 -04:00
|
|
|
})
|
|
|
|
class ComponentWithTemplate {
|
|
|
|
}
|
|
|
|
|
2016-04-12 12:40:37 -04:00
|
|
|
@Component({selector: 'sample', template: "some template"})
|
2015-10-06 20:03:37 -04:00
|
|
|
class ComponentWithViewTemplate {
|
|
|
|
}
|
|
|
|
|
2016-04-12 12:40:37 -04:00
|
|
|
@Component({selector: 'sample', templateUrl: "some template url", template: "some template"})
|
2015-10-06 20:03:37 -04:00
|
|
|
class ComponentWithViewTemplateUrl {
|
|
|
|
}
|
|
|
|
|
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-04-12 12:40:37 -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-04-12 12:40:37 -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
|
|
|
});
|
|
|
|
|
|
|
|
it('should throw when Component has no View decorator and no template is set', () => {
|
|
|
|
expect(() => resolver.resolve(ComponentWithoutView))
|
|
|
|
.toThrowErrorWith(
|
2016-04-12 12:40:37 -04:00
|
|
|
"Component 'ComponentWithoutView' must have either 'template' or 'templateUrl' set");
|
2015-10-06 20:03:37 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should throw when simple class has no View decorator and no template is set', () => {
|
|
|
|
expect(() => resolver.resolve(SimpleClass))
|
2016-04-12 12:40:37 -04:00
|
|
|
.toThrowErrorWith("Could not compile 'SimpleClass' because it is not a component.");
|
2015-10-06 20:03:37 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|