import { ddescribe, describe, it, iit, xit, expect, beforeEach, afterEach, inject, beforeEachProviders } from '@angular/core/testing/testing_internal'; import {provide} from '@angular/core'; import {Console} from '@angular/core/src/console'; import { TemplateParser, splitClasses, TEMPLATE_TRANSFORMS } from '@angular/compiler/src/template_parser'; import { CompileDirectiveMetadata, CompilePipeMetadata, CompileTypeMetadata, CompileTemplateMetadata, CompileProviderMetadata, CompileTokenMetadata, CompileDiDependencyMetadata, CompileQueryMetadata } from '@angular/compiler/src/compile_metadata'; import { templateVisitAll, TemplateAstVisitor, TemplateAst, NgContentAst, EmbeddedTemplateAst, ElementAst, ReferenceAst, VariableAst, BoundEventAst, BoundElementPropertyAst, BoundDirectivePropertyAst, AttrAst, BoundTextAst, TextAst, PropertyBindingType, DirectiveAst, ProviderAstType } from '@angular/compiler/src/template_ast'; import {identifierToken, Identifiers} from '../src/identifiers'; import {ElementSchemaRegistry} from '@angular/compiler/src/schema/element_schema_registry'; import {MockSchemaRegistry} from '@angular/compiler/testing'; import {Unparser} from './expression_parser/unparser'; import {TEST_PROVIDERS} from './test_bindings'; var expressionUnparser = new Unparser(); var someModuleUrl = 'package:someModule'; var MOCK_SCHEMA_REGISTRY = [ provide( ElementSchemaRegistry, {useValue: new MockSchemaRegistry({'invalidProp': false}, {'mappedAttr': 'mappedProp'})}) ]; export function main() { var ngIf; var parse; var console: ArrayConsole; function commonBeforeEach() { beforeEachProviders(() => { console = new ArrayConsole(); return [provide(Console, {useValue: console})]; }); beforeEach(inject([TemplateParser], (parser) => { var component = CompileDirectiveMetadata.create({ selector: 'root', type: new CompileTypeMetadata({moduleUrl: someModuleUrl, name: 'Root'}), isComponent: true }); ngIf = CompileDirectiveMetadata.create({ selector: '[ngIf]', type: new CompileTypeMetadata({moduleUrl: someModuleUrl, name: 'NgIf'}), inputs: ['ngIf'] }); parse = (template: string, directives: CompileDirectiveMetadata[], pipes: CompilePipeMetadata[] = null): TemplateAst[] => { if (pipes === null) { pipes = []; } return parser.parse(component, template, directives, pipes, 'TestComp'); }; })); } describe('TemplateParser template transform', () => { beforeEachProviders(() => [TEST_PROVIDERS, MOCK_SCHEMA_REGISTRY]); beforeEachProviders( () => [provide(TEMPLATE_TRANSFORMS, {useValue: new FooAstTransformer(), multi: true})]); describe('single', () => { commonBeforeEach(); it('should transform TemplateAST', () => { expect(humanizeTplAst(parse('
', []))).toEqual([[ElementAst, 'foo']]); }); }); describe('multiple', () => { beforeEachProviders( () => [provide(TEMPLATE_TRANSFORMS, {useValue: new BarAstTransformer(), multi: true})]); commonBeforeEach(); it('should compose transformers', () => { expect(humanizeTplAst(parse('
', []))).toEqual([[ElementAst, 'bar']]); }); }); }); describe('TemplateParser', () => { beforeEachProviders(() => [TEST_PROVIDERS, MOCK_SCHEMA_REGISTRY]); commonBeforeEach(); describe('parse', () => { describe('nodes without bindings', () => { it('should parse text nodes', () => { expect(humanizeTplAst(parse('a', []))).toEqual([[TextAst, 'a']]); }); it('should parse elements with attributes', () => { expect(humanizeTplAst(parse('
', []))) .toEqual([[ElementAst, 'div'], [AttrAst, 'a', 'b']]); }); }); it('should parse ngContent', () => { var parsed = parse('', []); expect(humanizeTplAst(parsed)).toEqual([[NgContentAst]]); }); it('should parse ngContent regardless the namespace', () => { var parsed = parse('', []); expect(humanizeTplAst(parsed)) .toEqual([ [ElementAst, ':svg:svg'], [NgContentAst], ]); }); it('should parse bound text nodes', () => { expect(humanizeTplAst(parse('{{a}}', []))).toEqual([[BoundTextAst, '{{ a }}']]); }); describe('bound properties', () => { it('should parse mixed case bound properties', () => { expect(humanizeTplAst(parse('
', []))) .toEqual([ [ElementAst, 'div'], [BoundElementPropertyAst, PropertyBindingType.Property, 'someProp', 'v', null] ]); }); it('should parse dash case bound properties', () => { expect(humanizeTplAst(parse('
', []))) .toEqual([ [ElementAst, 'div'], [BoundElementPropertyAst, PropertyBindingType.Property, 'some-prop', 'v', null] ]); }); it('should normalize property names via the element schema', () => { expect(humanizeTplAst(parse('
', []))) .toEqual([ [ElementAst, 'div'], [BoundElementPropertyAst, PropertyBindingType.Property, 'mappedProp', 'v', null] ]); }); it('should parse mixed case bound attributes', () => { expect(humanizeTplAst(parse('
', []))) .toEqual([ [ElementAst, 'div'], [BoundElementPropertyAst, PropertyBindingType.Attribute, 'someAttr', 'v', null] ]); }); it('should parse and dash case bound classes', () => { expect(humanizeTplAst(parse('
', []))) .toEqual([ [ElementAst, 'div'], [BoundElementPropertyAst, PropertyBindingType.Class, 'some-class', 'v', null] ]); }); it('should parse mixed case bound classes', () => { expect(humanizeTplAst(parse('
', []))) .toEqual([ [ElementAst, 'div'], [BoundElementPropertyAst, PropertyBindingType.Class, 'someClass', 'v', null] ]); }); it('should parse mixed case bound styles', () => { expect(humanizeTplAst(parse('
', []))) .toEqual([ [ElementAst, 'div'], [BoundElementPropertyAst, PropertyBindingType.Style, 'someStyle', 'v', null] ]); }); it('should report invalid prefixes', () => { expect(() => parse('

', [])) .toThrowError( `Template parse errors:\nInvalid property name 'atTr.foo' ("

][atTr.foo]>"): TestComp@0:3`); expect(() => parse('

', [])) .toThrowError( `Template parse errors:\nInvalid property name 'sTyle.foo' ("

][sTyle.foo]>"): TestComp@0:3`); expect(() => parse('

', [])) .toThrowError( `Template parse errors:\nInvalid property name 'Class.foo' ("

][Class.foo]>"): TestComp@0:3`); expect(() => parse('

', [])) .toThrowError( `Template parse errors:\nInvalid property name 'bar.foo' ("

][bar.foo]>"): TestComp@0:3`); }); it('should parse bound properties via [...] and not report them as attributes', () => { expect(humanizeTplAst(parse('

', []))) .toEqual([ [ElementAst, 'div'], [BoundElementPropertyAst, PropertyBindingType.Property, 'prop', 'v', null] ]); }); it('should parse bound properties via bind- and not report them as attributes', () => { expect(humanizeTplAst(parse('
', []))) .toEqual([ [ElementAst, 'div'], [BoundElementPropertyAst, PropertyBindingType.Property, 'prop', 'v', null] ]); }); it('should parse bound properties via {{...}} and not report them as attributes', () => { expect(humanizeTplAst(parse('
', []))) .toEqual([ [ElementAst, 'div'], [BoundElementPropertyAst, PropertyBindingType.Property, 'prop', '{{ v }}', null] ]); }); it('should parse bound properties via animate- and not report them as attributes', () => { expect(humanizeTplAst(parse('
', []))) .toEqual([ [ElementAst, 'div'], [BoundElementPropertyAst, PropertyBindingType.Animation, 'something', 'value2', null] ]); }); }); describe('events', () => { it('should parse bound events with a target', () => { expect(humanizeTplAst(parse('
', []))) .toEqual([[ElementAst, 'div'], [BoundEventAst, 'event', 'window', 'v']]); }); it('should parse bound events via (...) and not report them as attributes', () => { expect(humanizeTplAst(parse('
', []))) .toEqual([[ElementAst, 'div'], [BoundEventAst, 'event', null, 'v']]); }); it('should parse event names case sensitive', () => { expect(humanizeTplAst(parse('
', []))) .toEqual([[ElementAst, 'div'], [BoundEventAst, 'some-event', null, 'v']]); expect(humanizeTplAst(parse('
', []))) .toEqual([[ElementAst, 'div'], [BoundEventAst, 'someEvent', null, 'v']]); }); it('should parse bound events via on- and not report them as attributes', () => { expect(humanizeTplAst(parse('
', []))) .toEqual([[ElementAst, 'div'], [BoundEventAst, 'event', null, 'v']]); }); it('should allow events on explicit embedded templates that are emitted by a directive', () => { var dirA = CompileDirectiveMetadata.create({ selector: 'template', outputs: ['e'], type: new CompileTypeMetadata({moduleUrl: someModuleUrl, name: 'DirA'}) }); expect(humanizeTplAst(parse('', [dirA]))) .toEqual([ [EmbeddedTemplateAst], [BoundEventAst, 'e', null, 'f'], [DirectiveAst, dirA], ]); }); }); describe('bindon', () => { it('should parse bound events and properties via [(...)] and not report them as attributes', () => { expect(humanizeTplAst(parse('
', []))) .toEqual([ [ElementAst, 'div'], [BoundElementPropertyAst, PropertyBindingType.Property, 'prop', 'v', null], [BoundEventAst, 'propChange', null, 'v = $event'] ]); }); it('should parse bound events and properties via bindon- and not report them as attributes', () => { expect(humanizeTplAst(parse('
', []))) .toEqual([ [ElementAst, 'div'], [BoundElementPropertyAst, PropertyBindingType.Property, 'prop', 'v', null], [BoundEventAst, 'propChange', null, 'v = $event'] ]); }); }); describe('directives', () => { it('should order directives by the directives array in the View and match them only once', () => { var dirA = CompileDirectiveMetadata.create({ selector: '[a]', type: new CompileTypeMetadata({moduleUrl: someModuleUrl, name: 'DirA'}) }); var dirB = CompileDirectiveMetadata.create({ selector: '[b]', type: new CompileTypeMetadata({moduleUrl: someModuleUrl, name: 'DirB'}) }); var dirC = CompileDirectiveMetadata.create({ selector: '[c]', type: new CompileTypeMetadata({moduleUrl: someModuleUrl, name: 'DirC'}) }); expect(humanizeTplAst(parse('
', [dirA, dirB, dirC]))) .toEqual([ [ElementAst, 'div'], [AttrAst, 'a', ''], [AttrAst, 'c', ''], [AttrAst, 'b', ''], [AttrAst, 'a', ''], [AttrAst, 'b', ''], [DirectiveAst, dirA], [DirectiveAst, dirB], [DirectiveAst, dirC] ]); }); it('should locate directives in property bindings', () => { var dirA = CompileDirectiveMetadata.create({ selector: '[a=b]', type: new CompileTypeMetadata({moduleUrl: someModuleUrl, name: 'DirA'}) }); var dirB = CompileDirectiveMetadata.create({ selector: '[b]', type: new CompileTypeMetadata({moduleUrl: someModuleUrl, name: 'DirB'}) }); expect(humanizeTplAst(parse('
', [dirA, dirB]))) .toEqual([ [ElementAst, 'div'], [BoundElementPropertyAst, PropertyBindingType.Property, 'a', 'b', null], [DirectiveAst, dirA] ]); }); it('should locate directives in event bindings', () => { var dirA = CompileDirectiveMetadata.create({ selector: '[a]', type: new CompileTypeMetadata({moduleUrl: someModuleUrl, name: 'DirB'}) }); expect(humanizeTplAst(parse('
', [dirA]))) .toEqual( [[ElementAst, 'div'], [BoundEventAst, 'a', null, 'b'], [DirectiveAst, dirA]]); }); it('should parse directive host properties', () => { var dirA = CompileDirectiveMetadata.create({ selector: 'div', type: new CompileTypeMetadata({moduleUrl: someModuleUrl, name: 'DirA'}), host: {'[a]': 'expr'} }); expect(humanizeTplAst(parse('
', [dirA]))) .toEqual([ [ElementAst, 'div'], [DirectiveAst, dirA], [BoundElementPropertyAst, PropertyBindingType.Property, 'a', 'expr', null] ]); }); it('should parse directive host listeners', () => { var dirA = CompileDirectiveMetadata.create({ selector: 'div', type: new CompileTypeMetadata({moduleUrl: someModuleUrl, name: 'DirA'}), host: {'(a)': 'expr'} }); expect(humanizeTplAst(parse('
', [dirA]))) .toEqual( [[ElementAst, 'div'], [DirectiveAst, dirA], [BoundEventAst, 'a', null, 'expr']]); }); it('should parse directive properties', () => { var dirA = CompileDirectiveMetadata.create({ selector: 'div', type: new CompileTypeMetadata({moduleUrl: someModuleUrl, name: 'DirA'}), inputs: ['aProp'] }); expect(humanizeTplAst(parse('
', [dirA]))) .toEqual([ [ElementAst, 'div'], [DirectiveAst, dirA], [BoundDirectivePropertyAst, 'aProp', 'expr'] ]); }); it('should parse renamed directive properties', () => { var dirA = CompileDirectiveMetadata.create({ selector: 'div', type: new CompileTypeMetadata({moduleUrl: someModuleUrl, name: 'DirA'}), inputs: ['b:a'] }); expect(humanizeTplAst(parse('
', [dirA]))) .toEqual([ [ElementAst, 'div'], [DirectiveAst, dirA], [BoundDirectivePropertyAst, 'b', 'expr'] ]); }); it('should parse literal directive properties', () => { var dirA = CompileDirectiveMetadata.create({ selector: 'div', type: new CompileTypeMetadata({moduleUrl: someModuleUrl, name: 'DirA'}), inputs: ['a'] }); expect(humanizeTplAst(parse('
', [dirA]))) .toEqual([ [ElementAst, 'div'], [AttrAst, 'a', 'literal'], [DirectiveAst, dirA], [BoundDirectivePropertyAst, 'a', '"literal"'] ]); }); it('should favor explicit bound properties over literal properties', () => { var dirA = CompileDirectiveMetadata.create({ selector: 'div', type: new CompileTypeMetadata({moduleUrl: someModuleUrl, name: 'DirA'}), inputs: ['a'] }); expect(humanizeTplAst(parse('
', [dirA]))) .toEqual([ [ElementAst, 'div'], [AttrAst, 'a', 'literal'], [DirectiveAst, dirA], [BoundDirectivePropertyAst, 'a', '"literal2"'] ]); }); it('should support optional directive properties', () => { var dirA = CompileDirectiveMetadata.create({ selector: 'div', type: new CompileTypeMetadata({moduleUrl: someModuleUrl, name: 'Dir'}), inputs: ['a'] }); expect(humanizeTplAst(parse('
', [dirA]))) .toEqual([[ElementAst, 'div'], [DirectiveAst, dirA]]); }); }); describe('providers', () => { var nextProviderId; function createToken(value: string): CompileTokenMetadata { var token; if (value.startsWith('type:')) { token = new CompileTokenMetadata({ identifier: new CompileTypeMetadata({moduleUrl: someModuleUrl, name: value.substring(5)}) }); } else { token = new CompileTokenMetadata({value: value}); } return token; } function createDep(value: string): CompileDiDependencyMetadata { var isOptional = false; if (value.startsWith('optional:')) { isOptional = true; value = value.substring(9); } var isSelf = false; if (value.startsWith('self:')) { isSelf = true; value = value.substring(5); } var isHost = false; if (value.startsWith('host:')) { isHost = true; value = value.substring(5); } return new CompileDiDependencyMetadata( {token: createToken(value), isOptional: isOptional, isSelf: isSelf, isHost: isHost}); } function createProvider( token: string, {multi = false, deps = /*@ts2dart_const*/[ ]}: {multi?: boolean, deps?: string[]} = {}): CompileProviderMetadata { return new CompileProviderMetadata({ token: createToken(token), multi: multi, useClass: new CompileTypeMetadata({name: `provider${nextProviderId++}`}), deps: deps.map(createDep) }); } function createDir(selector: string, {providers = null, viewProviders = null, deps = /*@ts2dart_const*/[], queries = /*@ts2dart_const*/[]}: { providers?: CompileProviderMetadata[], viewProviders?: CompileProviderMetadata[], deps?: string[], queries?: string[] } = {}): CompileDirectiveMetadata { var isComponent = !selector.startsWith('['); return CompileDirectiveMetadata.create({ selector: selector, type: new CompileTypeMetadata( {moduleUrl: someModuleUrl, name: selector, diDeps: deps.map(createDep)}), isComponent: isComponent, template: new CompileTemplateMetadata({ngContentSelectors: []}), providers: providers, viewProviders: viewProviders, queries: queries.map((value) => new CompileQueryMetadata({selectors: [createToken(value)]})) }); } beforeEach(() => { nextProviderId = 0; }); it('should provide a component', () => { var comp = createDir('my-comp'); var elAst: ElementAst = parse('', [comp])[0]; expect(elAst.providers.length).toBe(1); expect(elAst.providers[0].providerType).toBe(ProviderAstType.Component); expect(elAst.providers[0].providers[0].useClass).toBe(comp.type); }); it('should provide a directive', () => { var dirA = createDir('[dirA]'); var elAst: ElementAst = parse('
', [dirA])[0]; expect(elAst.providers.length).toBe(1); expect(elAst.providers[0].providerType).toBe(ProviderAstType.Directive); expect(elAst.providers[0].providers[0].useClass).toBe(dirA.type); }); it('should use the public providers of a directive', () => { var provider = createProvider('service'); var dirA = createDir('[dirA]', {providers: [provider]}); var elAst: ElementAst = parse('
', [dirA])[0]; expect(elAst.providers.length).toBe(2); expect(elAst.providers[1].providerType).toBe(ProviderAstType.PublicService); expect(elAst.providers[1].providers).toEqual([provider]); }); it('should use the private providers of a component', () => { var provider = createProvider('service'); var comp = createDir('my-comp', {viewProviders: [provider]}); var elAst: ElementAst = parse('', [comp])[0]; expect(elAst.providers.length).toBe(2); expect(elAst.providers[1].providerType).toBe(ProviderAstType.PrivateService); expect(elAst.providers[1].providers).toEqual([provider]); }); it('should support multi providers', () => { var provider0 = createProvider('service0', {multi: true}); var provider1 = createProvider('service1', {multi: true}); var provider2 = createProvider('service0', {multi: true}); var dirA = createDir('[dirA]', {providers: [provider0, provider1]}); var dirB = createDir('[dirB]', {providers: [provider2]}); var elAst: ElementAst = parse('
', [dirA, dirB])[0]; expect(elAst.providers.length).toBe(4); expect(elAst.providers[2].providers).toEqual([provider0, provider2]); expect(elAst.providers[3].providers).toEqual([provider1]); }); it('should overwrite non multi providers', () => { var provider1 = createProvider('service0'); var provider2 = createProvider('service1'); var provider3 = createProvider('service0'); var dirA = createDir('[dirA]', {providers: [provider1, provider2]}); var dirB = createDir('[dirB]', {providers: [provider3]}); var elAst: ElementAst = parse('
', [dirA, dirB])[0]; expect(elAst.providers.length).toBe(4); expect(elAst.providers[2].providers).toEqual([provider3]); expect(elAst.providers[3].providers).toEqual([provider2]); }); it('should overwrite component providers by directive providers', () => { var compProvider = createProvider('service0'); var dirProvider = createProvider('service0'); var comp = createDir('my-comp', {providers: [compProvider]}); var dirA = createDir('[dirA]', {providers: [dirProvider]}); var elAst: ElementAst = parse('', [dirA, comp])[0]; expect(elAst.providers.length).toBe(3); expect(elAst.providers[2].providers).toEqual([dirProvider]); }); it('should overwrite view providers by directive providers', () => { var viewProvider = createProvider('service0'); var dirProvider = createProvider('service0'); var comp = createDir('my-comp', {viewProviders: [viewProvider]}); var dirA = createDir('[dirA]', {providers: [dirProvider]}); var elAst: ElementAst = parse('', [dirA, comp])[0]; expect(elAst.providers.length).toBe(3); expect(elAst.providers[2].providers).toEqual([dirProvider]); }); it('should overwrite directives by providers', () => { var dirProvider = createProvider('type:my-comp'); var comp = createDir('my-comp', {providers: [dirProvider]}); var elAst: ElementAst = parse('', [comp])[0]; expect(elAst.providers.length).toBe(1); expect(elAst.providers[0].providers).toEqual([dirProvider]); }); it('should throw if mixing multi and non multi providers', () => { var provider0 = createProvider('service0'); var provider1 = createProvider('service0', {multi: true}); var dirA = createDir('[dirA]', {providers: [provider0]}); var dirB = createDir('[dirB]', {providers: [provider1]}); expect(() => parse('
', [dirA, dirB])) .toThrowError( `Template parse errors:\n` + `Mixing multi and non multi provider is not possible for token service0 ("[ERROR ->]
"): TestComp@0:0`); }); it('should sort providers by their DI order', () => { var provider0 = createProvider('service0', {deps: ['type:[dir2]']}); var provider1 = createProvider('service1'); var dir2 = createDir('[dir2]', {deps: ['service1']}); var comp = createDir('my-comp', {providers: [provider0, provider1]}); var elAst: ElementAst = parse('', [comp, dir2])[0]; expect(elAst.providers.length).toBe(4); expect(elAst.providers[0].providers[0].useClass).toEqual(comp.type); expect(elAst.providers[1].providers).toEqual([provider1]); expect(elAst.providers[2].providers[0].useClass).toEqual(dir2.type); expect(elAst.providers[3].providers).toEqual([provider0]); }); it('should sort directives by their DI order', () => { var dir0 = createDir('[dir0]', {deps: ['type:my-comp']}); var dir1 = createDir('[dir1]', {deps: ['type:[dir0]']}); var dir2 = createDir('[dir2]', {deps: ['type:[dir1]']}); var comp = createDir('my-comp'); var elAst: ElementAst = parse('', [comp, dir2, dir0, dir1])[0]; expect(elAst.providers.length).toBe(4); expect(elAst.directives[0].directive).toBe(comp); expect(elAst.directives[1].directive).toBe(dir0); expect(elAst.directives[2].directive).toBe(dir1); expect(elAst.directives[3].directive).toBe(dir2); }); it('should mark directives and dependencies of directives as eager', () => { var provider0 = createProvider('service0'); var provider1 = createProvider('service1'); var dirA = createDir('[dirA]', {providers: [provider0, provider1], deps: ['service0']}); var elAst: ElementAst = parse('
', [dirA])[0]; expect(elAst.providers.length).toBe(3); expect(elAst.providers[0].providers).toEqual([provider0]); expect(elAst.providers[0].eager).toBe(true); expect(elAst.providers[1].providers[0].useClass).toEqual(dirA.type); expect(elAst.providers[1].eager).toBe(true); expect(elAst.providers[2].providers).toEqual([provider1]); expect(elAst.providers[2].eager).toBe(false); }); it('should mark dependencies on parent elements as eager', () => { var provider0 = createProvider('service0'); var provider1 = createProvider('service1'); var dirA = createDir('[dirA]', {providers: [provider0, provider1]}); var dirB = createDir('[dirB]', {deps: ['service0']}); var elAst: ElementAst = parse('
', [dirA, dirB])[0]; expect(elAst.providers.length).toBe(3); expect(elAst.providers[0].providers[0].useClass).toEqual(dirA.type); expect(elAst.providers[0].eager).toBe(true); expect(elAst.providers[1].providers).toEqual([provider0]); expect(elAst.providers[1].eager).toBe(true); expect(elAst.providers[2].providers).toEqual([provider1]); expect(elAst.providers[2].eager).toBe(false); }); it('should mark queried providers as eager', () => { var provider0 = createProvider('service0'); var provider1 = createProvider('service1'); var dirA = createDir('[dirA]', {providers: [provider0, provider1], queries: ['service0']}); var elAst: ElementAst = parse('
', [dirA])[0]; expect(elAst.providers.length).toBe(3); expect(elAst.providers[0].providers[0].useClass).toEqual(dirA.type); expect(elAst.providers[0].eager).toBe(true); expect(elAst.providers[1].providers).toEqual([provider0]); expect(elAst.providers[1].eager).toBe(true); expect(elAst.providers[2].providers).toEqual([provider1]); expect(elAst.providers[2].eager).toBe(false); }); it('should not mark dependencies accross embedded views as eager', () => { var provider0 = createProvider('service0'); var dirA = createDir('[dirA]', {providers: [provider0]}); var dirB = createDir('[dirB]', {deps: ['service0']}); var elAst: ElementAst = parse('
', [dirA, dirB])[0]; expect(elAst.providers.length).toBe(2); expect(elAst.providers[0].providers[0].useClass).toEqual(dirA.type); expect(elAst.providers[0].eager).toBe(true); expect(elAst.providers[1].providers).toEqual([provider0]); expect(elAst.providers[1].eager).toBe(false); }); it('should report missing @Self() deps as errors', () => { var dirA = createDir('[dirA]', {deps: ['self:provider0']}); expect(() => parse('
', [dirA])) .toThrowErrorWith( 'No provider for provider0 ("[ERROR ->]
"): TestComp@0:0'); }); it('should change missing @Self() that are optional to nulls', () => { var dirA = createDir('[dirA]', {deps: ['optional:self:provider0']}); var elAst: ElementAst = parse('
', [dirA])[0]; expect(elAst.providers[0].providers[0].deps[0].isValue).toBe(true); expect(elAst.providers[0].providers[0].deps[0].value).toBe(null); }); it('should report missing @Host() deps as errors', () => { var dirA = createDir('[dirA]', {deps: ['host:provider0']}); expect(() => parse('
', [dirA])) .toThrowErrorWith( 'No provider for provider0 ("[ERROR ->]
"): TestComp@0:0'); }); it('should change missing @Host() that are optional to nulls', () => { var dirA = createDir('[dirA]', {deps: ['optional:host:provider0']}); var elAst: ElementAst = parse('
', [dirA])[0]; expect(elAst.providers[0].providers[0].deps[0].isValue).toBe(true); expect(elAst.providers[0].providers[0].deps[0].value).toBe(null); }); }); describe('references', () => { it('should parse references via #... and not report them as attributes', () => { expect(humanizeTplAst(parse('
', []))) .toEqual([[ElementAst, 'div'], [ReferenceAst, 'a', null]]); }); it('should parse references via ref-... and not report them as attributes', () => { expect(humanizeTplAst(parse('
', []))) .toEqual([[ElementAst, 'div'], [ReferenceAst, 'a', null]]); }); it('should parse references via var-... and report them as deprecated', () => { expect(humanizeTplAst(parse('
', []))) .toEqual([[ElementAst, 'div'], [ReferenceAst, 'a', null]]); expect(console.warnings) .toEqual([ [ 'Template parse warnings:', '"var-" on non