如何使用测试外部css属性 jasmine-karma
.buy{
width: 50%;
}
<span class="buy">
Hello i want to check the width property
</span>
你不能检查 50
作为一个值,但你可以得到计算出的 width
值使用。
it('should create', () => {
expect(component).toBeTruthy();
const e = fixture.debugElement.query(By.css(".test")).nativeElement;
console.log(getComputedStyle(e).width)
// you can get value as '442.5px' or something
});
不建议检查这种微不足道的属性,除非是必须的。