javascript - 在 ie8 中使用 jasmine 比较数组失败

标签 javascript internet-explorer unit-testing jasmine

显然 ie8 具有三个属性,这些属性通过调用 String.prototype.match() 附加到结果数组:

inputindexlastIndex

( MSDN Documentation )

结果是使用 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([]);

http://underscorejs.org/#difference

关于javascript - 在 ie8 中使用 jasmine 比较数组失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11323691/

相关文章:

javascript - `$().clone(true)` 破坏 Chrome 扩展中的事件处理程序(适用于 jsbin)

php - 如何像在 php 中一样将 URL 变量传递给 express.js?

javascript - 允许用户向您的站点添加自己的 JavaScript 的安全问题?

php - 使用 Internet Explorer %u20AC 到 € 的 UTF-8 编码

javascript - 子类化并扩展 Jest 模拟的 Promise

java - 是否可以在一个节点上运行多个 Selenium 测试?

python - 如何在模拟类的对象上定义任意属性?

javascript - 在 Gatsby 中设置环境变量

html - IE 和 Chrome inline-block css 不同的行为

internet-explorer - jquery ajax 无法在 IE 中发送