我们有一个模版应用程序,它调用了wrap传单,样式函数需要将Function用作方法参数,模版不能做到这一点,因此我们传递一个对象,然后将其解析为一个函数,无论如何这都可行但是尝试用Jest进行测试会给我们带来麻烦。
代码
sh_main
测试
Sub Actual_inventory()
Assignments1
Dim directory As String, fileName As String, i As Integer
Dim col_unrestricted As String
Dim range_temp2 As Range
Application.ScreenUpdating = False
directory = "C:\Users\marcellh\Documents\Reports\Actual\"
fileName = Dir(directory & "*.xl??")
Workbooks.Open (directory & fileName)
'converts column A to number format:
Range("A:A").Select
With Selection
.NumberFormat = "General"
.Value = .Value
End With
'searches column "unrestricted":
Set range_temp2 = Workbooks(fileName).Sheets(1).Cells.Find("unrestricted")
col_unrestricted = range_temp2.Column
'---
i = first_data_set
Do While sh_main.Cells(i, col_color).Value <> ""
'vlookups based on old gmid, iferror then "":
sh_main.Cells(i, col_inventory_old_gmid).Value = Application.WorksheetFunction.VLookup(sh_main.Cells(i, col_old_gmid_code).Value, Workbooks(fileName).Sheets(1).Range("A:L"), col_unrestricted, False)
If IsError(sh_main.Cells(i, col_inventory_old_gmid).Value) Then
sh_main.Cells(i, col_inventory_old_gmid).Value = ""
End If
'vlookups based on new gmid, iferror then "":
sh_main.Cells(i, col_inventory_new_gmid).Value = Application.WorksheetFunction.VLookup(sh_main.Cells(i, col_new_gmid_code).Value, Workbooks(fileName).Sheets(1).Range("A:L"), col_unrestricted, False)
If IsError(sh_main.Cells(i, col_inventory_new_gmid).Value) Then
sh_main.Cells(i, col_inventory_new_gmid).Value = ""
End If
i = i + 1
Loop
Workbooks(fileName).Close
fileName = Dir()
Application.ScreenUpdating = True
MsgBox "Actual inventory has been loaded successfully"
End Sub
返回
public onStylesChange(newVal) {
this.geoJSONstyles = Function('return ('+newVal+')')(); //
if (this.geoJSON) {
this.geoJSON.setStyle(this.geoJSONstyles);
}
}
}
我该如何解决?
答案 0 :(得分:0)
不知道去年我的头在哪里,但是休息一下清除了我的想法。
我需要做的是在注释中向我指出的,因此,谢谢,是要检查类型,也可以将函数作为字符串返回并进行检查。 (忽略该函数的功能,仅用于测试分配) 所以
it('Should accept a string function and eval to a function', () => {
const testString = 'function () {return 0 }'
cut.onObjChangetest(String);
expect(typeof cut.onEachFeature === 'function').toBeTruthy();
expect(cut.geoJSONstyles.toString()).toBe(testString);
})
工作完美,测试通过了,呜! 谢谢