我已阅读其他主题,尝试了多种解决方案,但似乎没有任何效果。
测试:
it("parses string array", function(){
var usArr = ["integer.ImageViewer.main.RawBuffer", "dio.ImageViewer.main.performUnitCalibration"];
var newJson = [
{
fname : "integer.ImageViewer.main.RawBuffer",
con : "ImageViewer.main",
type : "integer",
vars : [{name : "RawBuffer"}]
},
{
fname : "dio.ImageViewer.main.performUnitCalibration",
con : "ImageViewer.main",
type : "dio",
vars : [{name : "performUnitCalibration"}]
}
];
expect(JFactory.parseToJSON(usArr)).toEqual(newJson);
})
错误讯息:
Expected
'[{"fname":"integer.ImageViewer.main.RawBuffer",
"com":"ImageViewer.main",
"type":"integer",
"vars":[{"name":"RawBuffer"}]},
{"fname":"dio.ImageViewer.main.performUnitCalibration",
"com":"ImageViewer.main",
"type":"dio",
"vars":[{"name":"performUnitCalibration"}]}]'
to equal
'[{"fname":"integer.ImageViewer.main.RawBuffer",
"con":"ImageViewer.main",
"type":"integer",
"vars":[{"name":"RawBuffer"}]},
{"fname":"dio.ImageViewer.main.performUnitCalibration",
"con":"ImageViewer.main",
"type":"dio",
"vars":[{"name":"performUnitCalibration"}]}]'.
Error: Expected
'[{"fname":"integer.ImageViewer.main.RawBuffer",
"com":"ImageViewer.main",
"type":"integer",
"vars":[{"name":"RawBuffer"}]},
{"fname":"dio.ImageViewer.main.performUnitCalibration",
"com":"ImageViewer.main",
"type":"dio",
"vars":[{"name":"performUnitCalibration"}]}]'
to equal
'[{"fname":"integer.ImageViewer.main.RawBuffer",
"con":"ImageViewer.main",
"type":"integer",
"vars":[{"name":"RawBuffer"}]},
{"fname":"dio.ImageViewer.main.performUnitCalibration",
"con":"ImageViewer.main",
"type":"dio",
"vars":[{"name":"performUnitCalibration"}]}]'.
我尝试过JSON字符串化两个对象,尝试过并试过:
expect(_.isEqual(JFactory.parseToJSON(usArr), newJson)).toEqual(true);
如此处所示:Jasmine toEqual for complex objects (mixed with functions) 这给了我: ReferenceError:_未定义
我完全迷失了,因为物体看起来完全一样。
答案 0 :(得分:2)
"com":"ImageViewer.main",
"con":"ImageViewer.main",
您正在将com
写入其中,con
写入另一个,它们绝对不相等。