feat(ivy): expose window.ng.getDebugNode helper (#32727)

PR Close #32727
This commit is contained in:
Matias Niemelä
2019-09-17 11:19:12 -07:00
committed by Andrew Kushnir
parent 252966bcca
commit 4726ac2481
6 changed files with 83 additions and 21 deletions

View File

@ -11,7 +11,7 @@ import {ComponentFixture, TestBed} from '@angular/core/testing';
import {onlyInIvy} from '@angular/private/testing';
import {getHostElement, markDirty} from '../../src/render3/index';
import {getComponent, getContext, getDirectives, getInjectionTokens, getInjector, getListeners, getLocalRefs, getRootComponents, getViewComponent, loadLContext} from '../../src/render3/util/discovery_utils';
import {getComponent, getContext, getDebugNode, getDirectives, getInjectionTokens, getInjector, getListeners, getLocalRefs, getRootComponents, getViewComponent, loadLContext} from '../../src/render3/util/discovery_utils';
onlyInIvy('Ivy-specific utilities').describe('discovery utils', () => {
let fixture: ComponentFixture<MyApp>;
@ -403,4 +403,31 @@ onlyInIvy('Ivy-specific utilities').describe('discovery utils deprecated', () =>
expect(localRefs.elRef.tagName.toLowerCase()).toBe('div');
});
});
describe('getDebugNode()', () => {
it('should create an instance of `DebugNode` when called for a specific element', () => {
@Component({
template: `
<div class="parent">
<div class="child"></div>
</div>
`
})
class Comp {
}
TestBed.configureTestingModule({declarations: [Comp]});
const fixture = TestBed.createComponent(Comp);
fixture.detectChanges();
const parent = fixture.nativeElement.querySelector('.parent') !;
const child = fixture.nativeElement.querySelector('.child') !;
const parentDebug = getDebugNode(parent) !;
const childDebug = getDebugNode(child) !;
expect(parentDebug.native).toBe(parent);
expect(childDebug.native).toBe(child);
});
});
});