显然 ie8 具有三个属性,这些属性通过调用 String.prototype.match()
附加到结果数组:
input
、index
和 lastIndex
结果是使用 Jasmine 的 .toEqual()
匹配器时数组比较失败。
我仍在努力学习单元测试的学习曲线,所以我很好奇处理这种失败的正确方法是什么。
以下工作但似乎有点蹩脚:
numArray = str.match(/\d+(\.\d+)?/g);
if (numArray && numArray.input) {
delete numArray.index;
delete numArray.input;
delete numArray.lastIndex;
}
最佳答案
Underscore 的“差异”方法可以提供帮助-
expect(_.difference(['item1', 'item2'], ['item1', 'item2'])).toEqual([]);
关于javascript - 在 ie8 中使用 jasmine 比较数组失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11323691/