import { ddescribe, describe, xdescribe, it, iit, xit, expect, beforeEach, afterEach, AsyncTestCompleter, inject, beforeEachBindings } from 'angular2/test_lib'; import {Promise, PromiseWrapper} from 'angular2/src/core/facade/async'; import {Type, isPresent, isBlank, stringify, isString} from 'angular2/src/core/facade/lang'; import {MapWrapper, SetWrapper, ListWrapper} from 'angular2/src/core/facade/collection'; import {RuntimeMetadataResolver} from 'angular2/src/compiler/runtime_metadata'; import { TemplateCompiler, NormalizedComponentWithViewDirectives } from 'angular2/src/compiler/template_compiler'; import {CompileDirectiveMetadata} from 'angular2/src/compiler/directive_metadata'; import {evalModule} from './eval_module'; import {SourceModule, moduleRef} from 'angular2/src/compiler/source_module'; import {XHR} from 'angular2/src/core/render/xhr'; import {MockXHR} from 'angular2/src/core/render/xhr_mock'; import {Locals} from 'angular2/src/core/change_detection/change_detection'; import { CommandVisitor, TextCmd, NgContentCmd, BeginElementCmd, BeginComponentCmd, EmbeddedTemplateCmd, TemplateCmd, visitAllCommands, CompiledTemplate } from 'angular2/src/core/compiler/template_commands'; import {Component, View, Directive} from 'angular2/core'; import {TEST_BINDINGS} from './test_bindings'; import {TestContext, TestDispatcher, TestPipes} from './change_detector_mocks'; import {codeGenValueFn, codeGenExportVariable} from 'angular2/src/compiler/util'; // Attention: This path has to point to this test file! const THIS_MODULE = 'angular2/test/compiler/template_compiler_spec'; var THIS_MODULE_REF = moduleRef(THIS_MODULE); export function main() { describe('TemplateCompiler', () => { var compiler: TemplateCompiler; var runtimeMetadataResolver: RuntimeMetadataResolver; beforeEachBindings(() => TEST_BINDINGS); beforeEach(inject([TemplateCompiler, RuntimeMetadataResolver], (_compiler, _runtimeMetadataResolver) => { compiler = _compiler; runtimeMetadataResolver = _runtimeMetadataResolver; })); describe('compile templates', () => { function runTests(compile) { it('should throw for non components', inject([AsyncTestCompleter], (async) => { PromiseWrapper.catchError(PromiseWrapper.wrap(() => compile([NonComponent])), (error) => { expect(error.message) .toEqual( `Could not compile '${stringify(NonComponent)}' because it is not a component.`); async.done(); }); })); it('should compile host components', inject([AsyncTestCompleter], (async) => { compile([CompWithBindingsAndStyles]) .then((humanizedTemplate) => { expect(humanizedTemplate['styles']).toEqual([]); expect(humanizedTemplate['commands'][0]).toEqual(''); expect(humanizedTemplate['cd']).toEqual(['elementProperty(title)=someDirValue']); async.done(); }); })); it('should compile nested components', inject([AsyncTestCompleter], (async) => { compile([CompWithBindingsAndStyles]) .then((humanizedTemplate) => { var nestedTemplate = humanizedTemplate['commands'][1]; expect(nestedTemplate['styles']).toEqual(['div {color: red}']); expect(nestedTemplate['commands'][0]).toEqual(''); expect(nestedTemplate['cd']).toEqual(['elementProperty(href)=someCtxValue']); async.done(); }); })); it('should compile recursive components', inject([AsyncTestCompleter], (async) => { compile([TreeComp]) .then((humanizedTemplate) => { expect(humanizedTemplate['commands'][0]).toEqual(''); expect(humanizedTemplate['commands'][1]['commands'][0]).toEqual(''); expect(humanizedTemplate['commands'][1]['commands'][1]['commands'][0]) .toEqual(''); async.done(); }); })); it('should pass the right change detector to embedded templates', inject([AsyncTestCompleter], (async) => { compile([CompWithEmbeddedTemplate]) .then((humanizedTemplate) => { expect(humanizedTemplate['commands'][1]['commands'][0]).toEqual('