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 元素样式


- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01