Angular 2 tests - get DOM element styles(Angular 2 测试 - 获取 DOM 元素样式)
问题描述
我想在我的 Angular 2 应用程序中测试我的隐藏显示按钮的功能(测试是用 Jasmine 编写的),所以我需要检查相关元素的 display
属性的值.如何使用 Angular 的 debugElement
获取此属性?测试代码:
I want to test the functionality of my hide-show button in my Angular 2 app(Tests are written in Jasmine), so I need to check the value of the display
property of the relevant element. How can I get this property using Angular's debugElement
?
Test code:
let input = fixture.debugElement.query(By.css('input'));
expect(input.styles['visibility']).toBe('false');
我得到错误:预期 undefined 为假".
I get the error: Expected undefined to be 'false'.
推荐答案
对于任何偶然发现这个例子的人来说,display
这个特定问题的解决方案是 hidden
属性在 debugElement
上.如果元素被隐藏,它将包含 true
,否则将包含 false
.
For anyone stumbling upon this example, the solution for this specific issue with display
is the hidden
property on the debugElement
. It will contain true
if the element is hidden and false
otherwise.
这篇关于Angular 2 测试 - 获取 DOM 元素样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Angular 2 测试 - 获取 DOM 元素样式


基础教程推荐
- 响应更改 div 大小保持纵横比 2022-01-01
- 动态更新多个选择框 2022-01-01
- 当用户滚动离开时如何暂停 youtube 嵌入 2022-01-01
- 角度Apollo设置WatchQuery结果为可用变量 2022-01-01
- 悬停时滑动输入并停留几秒钟 2022-01-01
- 在 JS 中获取客户端时区(不是 GMT 偏移量) 2022-01-01
- 有没有办法使用OpenLayers更改OpenStreetMap中某些要素 2022-09-06
- Karma-Jasmine:如何正确监视 Modal? 2022-01-01
- 我什么时候应该在导入时使用方括号 2022-01-01
- 在for循环中使用setTimeout 2022-01-01