我怎么能测试一个没有任何onBlur,onChange,onClick事件传递的方法。
该文件仅包含case,break和switch。所以我不确定如何开始这个文件。我已经测试了基础道具并且它正确渲染
使用IS - ENZYME REACT JS
另一种调用BuildShapeObj的方法
updateFilterList = (filterList) => {
let localFilters = Object.assign({}, this.state.filters)
// NOTE: need to change localFilters[props.currentColumnID] with filterList.column
localFilters[this.props.currentColumnID] = filterList
if (Object.keys(localFilters[this.props.currentColumnID]).length === 0) {
delete localFilters[this.props.currentColumnID]
}
let updateObj = this.buildShapeObj({switchValue: 'filtering', shapeObjValue: localFilters})
let updateBoolean = this.shouldUpdateViewXML(localFilters)
if (updateBoolean) {
this.props.updateViewXMLValue(updateObj)
}
this.setState({
filters: localFilters
})
}
这只是方法的一部分
buildShapeObj = updateObj => {
let pipe = "shape";
let shapeObj = {};
switch (updateObj.type) {
case "sort":
shapeObj = {
0: {
pipe,
action: "transform",
columnName: updateObj.column,
sort: updateObj.value
}
};
break;
case "group":
shapeObj = {
0: {
pipe,
columnName: updateObj.column,
transformType: "replaceElement",
matchValue: "resetanalysis"
},
1: {
pipe,
columnName: updateObj.column,
transformType: "replaceElement",
matchValue: "resetallgrouping"
}
// ...
};
break;
}
return shapeObj; //end of method line 350
};
如果有人可以协助设置,我将不胜感激谢谢
这是一个pure function所以测试它只是验证它根据给定的输入返回正确的输出:
describe('buildShapeObj', () => {
it('should handle sort', () => {
expect(buildShapeObj({
type: 'sort',
column: 'the column',
value: 'the value'
})).toEqual({
0: {
pipe: 'shape',
action: 'transform',
columnName: 'the column',
sort: 'the value'
}
}); // Success!
});
it('should handle group', () => {
expect(buildShapeObj({
type: 'group',
column: 'the column'
})).toEqual({
0: {
pipe: 'shape',
columnName: 'the column',
transformType: "replaceElement",
matchValue: "resetanalysis"
},
1: {
pipe: 'shape',
columnName: 'the column',
transformType: "replaceElement",
matchValue: "resetallgrouping"
}
}); // Success!
});
});