【发布时间】:2018-10-12 14:46:31
【问题描述】:
有什么方法可以测试元素的height css 属性吗?
我有一个函数可以改变div 的高度,如果能在测试中检查该函数是否正确运行会很好...
即:
<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。
【问题讨论】: