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).... (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 在vim中,如何摆脱烦人的“E141:没有缓冲区nn的文件名”
- angularjs – Angular UI Bootstrap模态更新$scope
- angularjs – 什么是“咕噜服务”抛出“没有鲍尔组件找到”
- 使用 BootstrapTable 实现数据的分页显示(一)
- UNIX一切皆文件的思想正确吗
- AngularJs ng-show 和 ng-if的区别
- WebServices接口的描述文件WSDL中经常出现name="in0
- 如何在Scala中将DataFrame导出到csv?
- mysql备份脚本-myisam引擎
- angularjs – 无法实例化控制器Angular New Router