假设我的 Angular 组件中有以下 HTML
<div name='my-name'>
something
</div>
Run Code Online (Sandbox Code Playgroud)
在我的测试用例中,如何name='my-name'使用属性按属性获取上述元素ComponentFixture?
尝试
const fixture = TestBed.createComponent(AppComponent);
const debugElement = fixture.debugElement;
const attributeEl = debugElement.query(By.css('div[name="my-name"]'));
Run Code Online (Sandbox Code Playgroud)
并确保导入来自import { By } from '@angular/platform-browser';
| 归档时间: |
|
| 查看次数: |
4294 次 |
| 最近记录: |