加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular – 是否有DOM nativeElement的typescript定义?

发布时间:2020-12-17 07:20:39 所属栏目:安全 来源:网络整理
导读:我正在测试一个Angular2组件,并希望断言组件的nativeElement属性,但它没有打字稿定义.我的测试看起来像这样: beforeEach( () = { myComponentFixture = TestBed.createComponent(MyComponent); myComponent = myComponentFixture.componentInstance;});it('
我正在测试一个Angular2组件,并希望断言组件的nativeElement属性,但它没有打字稿定义.我的测试看起来像这样:
beforeEach( () => {
    myComponentFixture = TestBed.createComponent(MyComponent);
    myComponent = myComponentFixture.componentInstance;
});

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

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

问题是我输入nativeElement后.没有IntelliSense,因为我认为nativeElement没有任何类型.我可能想要检查更多属性,如innerHtml,id等.这个示例测试可能没有意义,但我可以使用myComponentFixture.debugElement.query(By.css(‘#myElement’)测试一些特定DOM元素的属性).nativeElement

你需要施展.由于多平台策略,他们没有为nativeElement指定特定类型:
(myComponentFixture.nativeElement as HTMLElement)....

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读