簡體   English   中英

帶有角度的單元測試CSS

[英]Unit testing css with angular

有什么方法可以測試元素的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. 公開展示myDiv

  2. 設置組件的測試平台(通常默認情況下添加)

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM