显然,通过调用String.prototype.match(),ie8有三个属性被附加到结果数组中:
input、index和lastIndex
(MSDN Documentation)
结果是,当使用Jasmine的.toEqual()匹配器时,数组比较失败。
我仍然在单元测试的学习曲线上努力,所以我只是好奇处理这个失败的正确方法是什么。
下面的代码行得通,但看起来有点差劲:
numArray = str.match(/\d+(\.\d+)?/g);
if (numArray && numArray.input) {
delete numArray.index;
delete numArray.input;
delete numArray.lastIndex;
}发布于 2012-10-24 00:29:06
下划线的'difference‘方法可以帮助-
expect(_.difference(['item1', 'item2'], ['item1', 'item2'])).toEqual([]);http://underscorejs.org/#difference
发布于 2013-03-01 09:18:15
我认为@monkeyboy的答案不正确。
由于underscore.difference()返回的是第一个数组中没有出现在第二个数组中的元素:_.difference([1],[1,2]);也是[],所以测试会在不应该通过的时候通过,所以我找不到使用下划线的方法。
所以我使用:
expect(JSON.stringify(result)).toBe(JSON.stringify(expected));
它的工作方式与预期一致。
不管怎样,我想知道其他人是怎么做的。
https://stackoverflow.com/questions/11323691
复制相似问题