Error:Uncaught AssertionError: expected { Object (response) } to equal { Object (response) }

Error:Uncaught AssertionError: expected { Object (response) } to equal { Object (response) }

当我尝试做 deepEqual 时,我在测试用例中遇到了一个问题,我试图将结果数据的确切结构与示例数据进行比较。

以上是我根据实际数据创建的示例json数据。

代码:

it('comparing structures',()=>{
        var result = instance.parseResponse(input,esResponse);
        console.log(result);
        assert.deepEqual( result, expectedJSON);
    });

在控制台中我得到了结果。

根据我正在创建示例数据的结果。

代码:

    var expectedJSON={
    "response":{
    "aggregate":{
        "average":43.833333333333336,
        "count":6,
        "max":90,
        "min":10,
        "total":263
    },
    "endDate":"Tue Jul 05 2016 05:30:00 GMT+0530 (India Standard Time)",
    "groupBy":"datetime",
    "metricType":"distance_metric",
    "quarters":[{
        "aggregate":{
            "average":0,
            "count":undefined,
            "max":0,
            "min":0,
            "total":0
        },
        "quarter":4,
        "startDate":"Invalid Date"
    }],
    "startDate":"Tue Jan 12 2016 05:30:00 GMT+0530 (India Standard Time)",
    "type":"person"
}
};

我这样做是因为我需要创建准确的 Json 结构并让任何结果都可能是该结构应该匹配的结果。

但是我得到了失败的测试用例

当您使用 deepEqual 时,它不仅会检查对象的结构,还会检查对象的类型。在这种情况下,它由 __proto__

给出

deepEqual 有很多问题,现在已经过时了。许多新的 ECMA 功能也不支持。我发现这个非常有趣:https://github.com/zubuzon/kewlr