0

我已经阅读了其他线程,尝试了多种解决方案,但似乎没有任何效果。

测试:

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: _ is not defined

我完全迷失了,因为这些物体似乎完全一样。

4

1 回答 1

2
"com":"ImageViewer.main",

"con":"ImageViewer.main",

你在写com一个和con另一个,它们肯定是不相等的。

于 2014-05-21T15:30:47.300 回答