尝试使用酶和开玩笑针对React Js测试以下方法。 某些行已覆盖,但由于情况和中断而丢失了一些。
onSortedChange = (obj) => {
let temp = '&$expand=SECURITY,POLICY1,ACCOUNT';
let tempBaseOrderby = '';
let desc = obj[0].desc ? ' desc' : ''
//&$expand=ACCOUNT,SECURITY,POLICY1
switch(obj[0].id) {
case 'AccountName':
temp = `&$expand=SECURITY,POLICY1,ACCOUNT&$orderby=ACCOUNT/AccountName${desc}`
break;
case 'SecurityName':
temp = `&$expand=SECURITY,POLICY1,ACCOUNT&$orderby=SECURITY/SecurityName${desc}`
break; //coverage missing
default:
tempBaseOrderby = `&$orderby=${obj[0].id}${desc}`
break;
}
this.setState({expand: temp, orderby:tempBaseOrderby}, ()=> {this.searchUnsubscribed()});
}
我能够调用该方法并测试其setState,但不确定如何将大小写/中断作为条件以正确测试 使用MemoryRouter并安装以进行测试:
it ('Test onSortedChange method',() => {
wrapper.find('Unsubscribe').setState({
expand:{},
orderby:{},
loading: true,
});
wrapper.update();
expect(wrapper.find('Unsubscribe').instance(). onSortedChange('test')).toEqual();
expect(wrapper.find('Unsubscribe').state('loading')).toBeTruthy();
});