Angular 等待元素出现在dom中,然后执行代码6单元测试
我需要等待元素加载到dom中,以便检查它包含的文本字符串 到目前为止,我尝试了,Angular 等待元素出现在dom中,然后执行代码6单元测试,angular,unit-testing,karma-jasmine,typescript2.0,Angular,Unit Testing,Karma Jasmine,Typescript2.0,我需要等待元素加载到dom中,以便检查它包含的文本字符串 到目前为止,我尝试了,fixture.whenStable()。然后,但没有成功。如何等待元素加载到dom中 it( 'should change the text value for the element', function() { let testDropdown : HTMLElement; const debugElement : DebugElement = fixture.debugElement;
fixture.whenStable()。然后
,但没有成功。如何等待元素加载到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 );
} );
一旦我更改了选择选项,即相同的选择选项文本,我将设置为图例元素。我需要等待该图例项加载。该元素将异步加载
有什么建议吗?如何继续?提供
组件
和规范
文件代码,以便我们可以查看您的end@ShashankVivek添加了一些示例代码,请检查。让我知道,如果还需要更多信息,请也添加您的组件
。每次expect之后触发更改检测的原因是什么?请提供组件
和规范
文件代码,以便我们可以查看您的end@ShashankVivek添加了一些示例代码,请检查。让我知道,如果还需要更多信息,请也添加您的组件
。每次预期后触发更改检测的原因是什么?