有什么方法可以测试元素的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”。
答案 0 :(得分:4)
像这样...
公开公开myDiv
设置组件的测试平台(通常默认情况下添加)
添加
component.myFunct(); expect(component.myDiv.nativeElement.style.height).toBe(500);