angular - 等待元素出现在dom中然后执行代码angular 6单元测试
问题描述
我需要等待元素被加载到 dom 中,所以我需要检查它包含的文本字符串。
我试过到目前为止,fixture.whenStable().then
但没有奏效。我如何等待元素直到它加载到 dom 中。
it( 'should change the text value for the element', function() {
let testDropdown : HTMLElement;
const debugElement : DebugElement = fixture.debugElement;
fixture.detectChanges();
testDropdown = debugElement.queryAll( By.css( 'mat-select' ) )[ 0 ].nativeElement;
testDropdown.click();
fixture.detectChanges();
debugElement.queryAll( By.css( 'mat-option' ) )[ 1 ].nativeElement.click();
fixture.detectChanges();
expect( testDropdown.getAttribute( 'ng-reflect-value' ) ).toEqual( 'Text 2' );
fixture.detectChanges();
const elementTitle = debugElement.queryAll( By.css( '.legend' ) );
console.log( elementTitle );
} );
一旦我更改了选择选项,相同的选择选项文本,我将设置为图例元素。我需要等待那个图例项被加载。该元素将异步加载。
有什么建议么?我该如何进行?
解决方案
推荐阅读
- typescript - 无法将严格为 false 的自由形式对象实体模型分配
- python - How to connect to Spark master in Swarm mode from host
- sql-server - 使用 SaveFileDialog vb.net 备份 SQL Server 数据库
- r - 使用向量更改多个列名
- python - 导入tensorflow时出现很多警告
- android - 导航组件 - 共享元素转换根本不起作用
- java - 当我想运行项目时如何修复'log 4 j logger'?
- android - Android 许可协议是否与 Android SDK 许可协议相同?
- firebase - Firestore 集合写入速率
- python - 使用 Python 将不同工作簿中的数据复制到主工作簿中