feat(viewport): add initial integration test for template directives
This commit is contained in:
parent
0758165fb5
commit
7bc282d15e
|
@ -10,10 +10,11 @@ import {Lexer} from 'change_detection/parser/lexer';
|
|||
import {Compiler} from 'core/compiler/compiler';
|
||||
import {DirectiveMetadataReader} from 'core/compiler/directive_metadata_reader';
|
||||
|
||||
import {Component} from 'core/annotations/annotations';
|
||||
import {Decorator} from 'core/annotations/annotations';
|
||||
import {Decorator, Component, Template} from 'core/annotations/annotations';
|
||||
import {TemplateConfig} from 'core/annotations/template_config';
|
||||
|
||||
import {ViewPort} from 'core/compiler/viewport';
|
||||
|
||||
export function main() {
|
||||
describe('integration tests', function() {
|
||||
var compiler;
|
||||
|
@ -76,6 +77,36 @@ export function main() {
|
|||
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({
|
||||
template: new TemplateConfig({
|
||||
directives: [MyDir, ChildComp]
|
||||
directives: [MyDir, ChildComp, SomeTemplate]
|
||||
})
|
||||
})
|
||||
class MyComp {
|
||||
|
@ -118,6 +149,16 @@ class ChildComp {
|
|||
}
|
||||
}
|
||||
|
||||
@Template({
|
||||
selector: '[some-tmpl]'
|
||||
})
|
||||
class SomeTemplate {
|
||||
constructor(viewPort: ViewPort) {
|
||||
viewPort.create();
|
||||
viewPort.create();
|
||||
}
|
||||
}
|
||||
|
||||
class MyService {
|
||||
greeting:string;
|
||||
constructor() {
|
||||
|
|
Loading…
Reference in New Issue