带有角度的单元测试CSS

时间:2018-10-12 14:46:32

标签: html css angular testing

有什么方法可以测试元素的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”。

1 个答案:

答案 0 :(得分:4)

像这样...

  1. 公开公开myDiv

  2. 设置组件的测试平台(通常默认情况下添加)

  3. 添加

component.myFunct();

expect(component.myDiv.nativeElement.style.height).toBe(500);