2012-07-04 17 views
1

顯然IE8具有獲得附加到從呼叫所得陣列String.prototype.match()三個屬性:使用茉莉比較陣列失敗在IE8

inputindexlastIndex

MSDN Documentation

的結果是當使用Jasmine's .toEqual()匹配器時,數組比較失敗。

我仍然在單元測試的學習曲線上工作,所以我只是好奇正確的方法來處理這個失敗。

下面的作品,但似乎有點跛:

numArray = str.match(/\d+(\.\d+)?/g); 
if (numArray && numArray.input) { 
     delete numArray.index; 
     delete numArray.input; 
     delete numArray.lastIndex; 
} 

回答

1

我覺得@ monkeyboy的答案是不正確的。

由於underscore.difference()返回第二個數組中不存在的第一個數組的元素:_.difference([1],[1,2]);也是[]因此測試在不應該時會通過。我找不到用下劃線解決這個問題的方法。

所以我使用:

expect(JSON.stringify(result)).toBe(JSON.stringify(expected));

預期其工作。

無論如何,我想知道別人是如何做到這一點。