Angular 2测试 - 获取DOM元素样式 [英] Angular 2 tests - get DOM element styles
问题描述
我想在我的Angular 2应用程序中测试我的隐藏显示按钮的功能(测试是用Jasmine编写的),所以我需要检查显示的值
相关要素的财产。如何使用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');
我收到错误:
预期未定义为'false'。
I get the error: Expected undefined to be 'false'.
推荐答案
对于任何绊倒此示例的人来说, display
的此特定问题的解决方案是 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元素样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!