【发布时间】:2018-08-31 08:47:51
【问题描述】:
我有一个组件,它接受一个参数作为一种指令来在其模板中设置<div> 的大小,现在唯一的问题是我不确定如何测试它?
我这样调用我的组件,其中small 可以替换为其他预定义的大小,例如medium/large 等:
<spinner small></spinner>
然后我将其作为@Input(<size>) 并执行设置以更改大小变量,然后将其传递给[ngStyle] 以更改显示组件大小的CSS。
component.ts
size: number;
@Input('small') set small(value) {
this.size = !value ? 25 : this.size;
}
get getSize() {
const myStyle = {
width: this.size + 'px',
height: this.size + 'px'
};
return myStyle;
}
component.html
<div [ngStyle]="getSize"></div>
我已经成功测试了get getSize() 函数,但是我对@Input(<val>) set 函数有点卡住了:-/
【问题讨论】:
标签: javascript angular typescript testing karma-runner