diff --git a/packages/core/test/acceptance/di_spec.ts b/packages/core/test/acceptance/di_spec.ts index 2c4f516c10..f0baec7bc8 100644 --- a/packages/core/test/acceptance/di_spec.ts +++ b/packages/core/test/acceptance/di_spec.ts @@ -860,6 +860,47 @@ describe('di', () => { }); }); + describe('inject', () => { + + it('should inject from parent view', () => { + @Directive({selector: '[parentDir]'}) + class ParentDirective { + } + + @Directive({selector: '[childDir]', exportAs: 'childDir'}) + class ChildDirective { + value: string; + constructor(public parent: ParentDirective) { this.value = parent.constructor.name; } + } + + @Directive({selector: '[child2Dir]', exportAs: 'child2Dir'}) + class Child2Directive { + value: boolean; + constructor(parent: ParentDirective, child: ChildDirective) { + this.value = parent === child.parent; + } + } + + @Component({ + template: `
+ + {{ child1.value }}-{{ child2.value }} + +
` + }) + class MyComp { + showing = true; + } + TestBed.configureTestingModule( + {declarations: [ParentDirective, ChildDirective, Child2Directive, MyComp]}); + const fixture = TestBed.createComponent(MyComp); + fixture.detectChanges(); + + const divElement = fixture.nativeElement.querySelector('div'); + expect(divElement.textContent).toBe('ParentDirective-true'); + }); + }); + describe('Special tokens', () => { describe('Injector', () => { diff --git a/packages/core/test/render3/di_spec.ts b/packages/core/test/render3/di_spec.ts index b57087169f..7ad45750f1 100644 --- a/packages/core/test/render3/di_spec.ts +++ b/packages/core/test/render3/di_spec.ts @@ -526,6 +526,9 @@ describe('di', () => { }); }); + /** + * This test needs to be moved to acceptance/di_spec.ts when Ivy compiler supports inline views. + */ it('should inject from parent view', () => { const ParentDirective = createDirective('parentDir'); @@ -593,10 +596,6 @@ describe('di', () => { expect(fixture.html) .toEqual('
Directive-true
'); }); - - it('should inject from module Injector', () => { - - }); }); describe('getOrCreateNodeInjector', () => {