Is there a typescript definition for DOM nativeElement?

I am testing an Angular2 component and want to assert the component's nativeElement property, but there is no typescript definition for it. My test is as follows:

beforeEach( () => {
    myComponentFixture = TestBed.createComponent(MyComponent);
    myComponent = myComponentFixture.componentInstance;
});

it('Should display something', fakeAsync(() => {
    myComponentFixture.detectChanges();

    expect(myComponentFixture.nativeElement.textContent).toContain('something');
}));

The problem is that after I type nativeElement., there is no IntelliSense for it, because I think there are no typings for nativeElement. There are more properties that I can check as innerHtml, id, etc. This test example may not make sense, but I can test some specific properties of the DOM element withmyComponentFixture.debugElement.query(By.css('#myElement')).nativeElement

+4
source share
2 answers

. - nativeElement:

(myComponentFixture.nativeElement as HTMLElement)....
+10

ElementRef Angular:

import { ElementRef } from '@angular/core';

0

Source: https://habr.com/ru/post/1663228/


All Articles