import { ddescribe, describe, xdescribe, it, iit, xit, expect, beforeEach, afterEach, AsyncTestCompleter, inject, beforeEachProviders } from 'angular2/testing_internal'; import {Promise, PromiseWrapper} from 'angular2/src/facade/async'; import {Type, isPresent, isBlank, stringify, isString} from 'angular2/src/facade/lang'; import {MapWrapper, SetWrapper, ListWrapper} from 'angular2/src/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/compiler/xhr'; import {MockXHR} from 'angular2/src/compiler/xhr_mock'; import {ViewEncapsulation} from 'angular2/src/core/metadata/view'; import {Locals} from 'angular2/src/core/change_detection/change_detection'; import { CommandVisitor, TextCmd, NgContentCmd, BeginElementCmd, BeginComponentCmd, EmbeddedTemplateCmd, TemplateCmd, visitAllCommands, CompiledComponentTemplate } from 'angular2/src/core/linker/template_commands'; import {Component, View, Directive, provide} from 'angular2/core'; import {TEST_PROVIDERS} from './test_bindings'; import {TestDispatcher, TestPipes} from './change_detector_mocks'; import {codeGenValueFn, codeGenExportVariable, MODULE_SUFFIX} from 'angular2/src/compiler/util'; // Attention: This path has to point to this test file! const THIS_MODULE_ID = 'angular2/test/compiler/template_compiler_spec'; var THIS_MODULE_REF = moduleRef(`package:${THIS_MODULE_ID}${MODULE_SUFFIX}`); export function main() { describe('TemplateCompiler', () => { var compiler: TemplateCompiler; var runtimeMetadataResolver: RuntimeMetadataResolver; beforeEachProviders(() => TEST_PROVIDERS); 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('