angular - 按属性名称获取元素 - Angular 测试
问题描述
说,我在我的 Angular 组件中有以下 HTML
<div name='my-name'>
something
</div>
在我的测试用例中,如何name='my-name'
使用属性获取上述元素ComponentFixture
?
解决方案
尝试
const fixture = TestBed.createComponent(AppComponent);
const debugElement = fixture.debugElement;
const attributeEl = debugElement.query(By.css('div[name="my-name"]'));
并确保从import { By } from '@angular/platform-browser';
推荐阅读
- f# - 使用接受字符串和列表的构造函数创建类型
- java - 为什么 Chronicle Queue 在关闭后会保留文件一秒钟?
- json - 在 ForEach 循环中使用 powershell 输出 JSON
- c - Switch case 0:输入0和输入字母
- javascript - 延迟 url 链接显示在左角
- reactjs - validate.js 验证数组
- python - Python中的max和Min函数问题
- python-3.x - TypeError: __call__() 接受 2 个位置参数,但在制作神经网络时给出了 3 个
- python - 在 Django Web Project 中,我的应用程序无法识别
- excel - Excel 到 DataTable(导入时缺少数据)