feat(viewport): add initial integration test for template directives

This commit is contained in:
Tobias Bosch 2014-12-01 15:26:53 -08:00
parent 0758165fb5
commit 7bc282d15e
1 changed files with 44 additions and 3 deletions

View File

@ -10,10 +10,11 @@ import {Lexer} from 'change_detection/parser/lexer';
import {Compiler} from 'core/compiler/compiler'; import {Compiler} from 'core/compiler/compiler';
import {DirectiveMetadataReader} from 'core/compiler/directive_metadata_reader'; import {DirectiveMetadataReader} from 'core/compiler/directive_metadata_reader';
import {Component} from 'core/annotations/annotations'; import {Decorator, Component, Template} from 'core/annotations/annotations';
import {Decorator} from 'core/annotations/annotations';
import {TemplateConfig} from 'core/annotations/template_config'; import {TemplateConfig} from 'core/annotations/template_config';
import {ViewPort} from 'core/compiler/viewport';
export function main() { export function main() {
describe('integration tests', function() { describe('integration tests', function() {
var compiler; var compiler;
@ -76,6 +77,36 @@ export function main() {
done(); done();
}); });
}); });
it('should support template directives via `<template>` elements.', (done) => {
compiler.compile(MyComp, createElement('<div><template some-tmpl><copy-me>hello</copy-me></template></div>')).then((pv) => {
createView(pv);
cd.detectChanges();
var childNodesOfWrapper = view.nodes[0].childNodes;
// 1 template + 2 copies.
expect(childNodesOfWrapper.length).toBe(3);
expect(childNodesOfWrapper[1].childNodes[0].nodeValue).toEqual('hello');
expect(childNodesOfWrapper[2].childNodes[0].nodeValue).toEqual('hello');
done();
});
});
it('should support template directives via `template` attribute.', (done) => {
compiler.compile(MyComp, createElement('<div><copy-me template="some-tmpl">hello</copy-me></div>')).then((pv) => {
createView(pv);
cd.detectChanges();
var childNodesOfWrapper = view.nodes[0].childNodes;
// 1 template + 2 copies.
expect(childNodesOfWrapper.length).toBe(3);
expect(childNodesOfWrapper[1].childNodes[0].nodeValue).toEqual('hello');
expect(childNodesOfWrapper[2].childNodes[0].nodeValue).toEqual('hello');
done();
});
});
}); });
}); });
} }
@ -93,7 +124,7 @@ class MyDir {
@Component({ @Component({
template: new TemplateConfig({ template: new TemplateConfig({
directives: [MyDir, ChildComp] directives: [MyDir, ChildComp, SomeTemplate]
}) })
}) })
class MyComp { class MyComp {
@ -118,6 +149,16 @@ class ChildComp {
} }
} }
@Template({
selector: '[some-tmpl]'
})
class SomeTemplate {
constructor(viewPort: ViewPort) {
viewPort.create();
viewPort.create();
}
}
class MyService { class MyService {
greeting:string; greeting:string;
constructor() { constructor() {