
[英]Angular 4 - Unit testing using Jasmine - Button click code showing error
[英]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。
像這樣
公開展示myDiv
設置組件的測試平台(通常默認情況下添加)
加
component.myFunct(); expect(component.myDiv.nativeElement.style.height).toBe(500);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.