chai按值

时间:2017-01-11 16:12:56

标签: javascript unit-testing assert chai

是否可以使用chai按值声明对象数组?

这是我的代码:

var expected = [
    {
        a: 10
    }
];

var actual = [
    {
        a: '10'
    }
];

// ...

assert.sameDeepMembers(expected, actual);

它给了我以下错误:

AssertionError: expected [ { a: 10 } ] to have the same members as [ { a: '10' } ]

所以我希望chai忽略属性的类型:a。

1 个答案:

答案 0 :(得分:1)

您的类型不同。根据chai对sameDeepMembers的定义:

Asserts that set1 and set2 have the same members - using a deep equality checking. Order is not taken into account.

javascript中的深度相等是===因此预期int类型10不相同且字符串类型'10'

(10 === '10') // false

也许chai的assert.sameMembers就是你要找的。