From 821f008462abdb24a18d4852bfe3fe04d8695823 Mon Sep 17 00:00:00 2001 From: Jeremy Elbourn Date: Wed, 18 Feb 2015 12:12:36 -0800 Subject: [PATCH] chore(compiler): add integration tests for @Parent and @Ancestor --- .../test/core/compiler/integration_spec.js | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/modules/angular2/test/core/compiler/integration_spec.js b/modules/angular2/test/core/compiler/integration_spec.js index e3f25d0e4e..2914c366a5 100644 --- a/modules/angular2/test/core/compiler/integration_spec.js +++ b/modules/angular2/test/core/compiler/integration_spec.js @@ -16,6 +16,7 @@ import {BindingPropagationConfig} from 'angular2/src/core/compiler/binding_propa import {Decorator, Component, Viewport} from 'angular2/src/core/annotations/annotations'; import {Template} from 'angular2/src/core/annotations/template'; +import {Parent, Ancestor} from 'angular2/src/core/annotations/visibility'; import {ViewContainer} from 'angular2/src/core/compiler/view_container'; @@ -296,6 +297,43 @@ export function main() { done(); }) }); + + it('should create a component that injects a @Parent', (done) => { + tplResolver.setTemplate(MyComp, new Template({ + inline: '', + directives: [SomeDirective, CompWithParent] + })); + + compiler.compile(MyComp).then((pv) => { + createView(pv); + + var childComponent = view.contextWithLocals.get('child'); + expect(childComponent.myParent).toBeAnInstanceOf(SomeDirective); + + done(); + }) + }); + + it('should create a component that injects an @Ancestor', (done) => { + tplResolver.setTemplate(MyComp, new Template({ + inline: ` + +

+ +

+
`, + directives: [SomeDirective, CompWithAncestor] + })); + + compiler.compile(MyComp).then((pv) => { + createView(pv); + + var childComponent = view.contextWithLocals.get('child'); + expect(childComponent.myAncestor).toBeAnInstanceOf(SomeDirective); + + done(); + }) + }); }); }); } @@ -358,6 +396,39 @@ class ChildComp { } } +@Decorator({ + selector: 'some-directive' +}) +class SomeDirective { } + +@Component({ + selector: 'cmp-with-parent' +}) +@Template({ + inline: '

Component with an injected parent

', + directives: [SomeDirective] +}) +class CompWithParent { + myParent: SomeDirective; + constructor(@Parent() someComp: SomeDirective) { + this.myParent = someComp; + } +} + +@Component({ + selector: 'cmp-with-ancestor' +}) +@Template({ + inline: '

Component with an injected ancestor

', + directives: [SomeDirective] +}) +class CompWithAncestor { + myAncestor: SomeDirective; + constructor(@Ancestor() someComp: SomeDirective) { + this.myAncestor = someComp; + } +} + @Viewport({ selector: '[some-viewport]' })