fix(ivy): ensure window.ng.getDebugNode returns debug info for component elements (#32780)

Prior to this patch the `window.ng.getDebugNode` method would fail to
return the debug information for an element that is a host element to
a component.

PR Close #32780
This commit is contained in:
Matias Niemelä
2019-09-19 15:01:08 -07:00
committed by Andrew Kushnir
parent 353368cccd
commit 5651fa3a95
3 changed files with 47 additions and 15 deletions

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {CommonModule} from '@angular/common';
import {Component, Directive, InjectionToken, ViewChild} from '@angular/core';
import {Component, Directive, HostBinding, InjectionToken, ViewChild} from '@angular/core';
import {ComponentFixture, TestBed} from '@angular/core/testing';
import {onlyInIvy} from '@angular/private/testing';
@ -429,5 +429,39 @@ onlyInIvy('Ivy-specific utilities').describe('discovery utils deprecated', () =>
expect(parentDebug.native).toBe(parent);
expect(childDebug.native).toBe(child);
});
it('should be able to pull debug information for a component host element', () => {
@Component({
selector: 'child-comp',
template: `
child comp
`
})
class ChildComp {
@HostBinding('style') public styles = {width: '200px', height: '400px'};
}
@Component({
template: `
<child-comp></child-comp>
`
})
class Comp {
}
TestBed.configureTestingModule({declarations: [Comp, ChildComp]});
const fixture = TestBed.createComponent(Comp);
fixture.detectChanges();
const child = fixture.nativeElement.querySelector('child-comp') !;
const childDebug = getDebugNode(child) !;
expect(childDebug.native).toBe(child);
expect(childDebug.styles).toBeTruthy();
const styles = childDebug.styles !.values;
expect(styles['width']).toEqual('200px');
expect(styles['height']).toEqual('400px');
});
});
});