html - 带角度的单元测试css
问题描述
有什么方法可以测试height
元素的 css 属性吗?
我有一个函数可以改变 a 的高度,div
最好在测试中检查该函数是否正确运行......
IE:
<div #myDiv>Hello world</div>
@ViewChild('myDiv') myDiv: ElementRef;
myFunct() {
this.myDiv.nativeElement.style.height = 500;
}
it('should increase div size', () => {
// Here is where I get stuck...
});
更新
实施测试,例如:
it('should return correct height of dropdown when initialised', () => {
component.myFunct();
expect(component.dropdown.nativeElement.style.height).toBe(34);
});
导致测试失败并显示以下消息:
预计 '' 为 500。
解决方案
像这样的东西...
公开暴露 myDiv
为组件设置测试台(通常默认添加)
添加
component.myFunct(); expect(component.myDiv.nativeElement.style.height).toBe(500);
推荐阅读
- javascript - 如何在 React-native 中加载脚本?
- java - 将外部 jar 添加到 Maven 存储库不起作用
- javascript - 如何在html中循环随机化javascript函数
- javascript - 在Nodejs中使用axios多次获取请求
- nginx - 通过 Cloudflare 后面的站点阻止使用 NGINX 的直接 IP 访问
- javascript - 如何使用jQuery动态获取复选框检查的列值的总和
- python - 切换 Homebrew 安装的 Python 版本(3.9 → 3.8)
- php - 获取当前子类别产品拇指 Woocommerce
- scala - Spark Scala DateType 模式执行错误
- java - 从 Material Card View Group 继承时丢失样式