问题描述
我想在我的 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 元素样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)