Using jasmine to compare arrays fails in ie8

Apparently ie8 has three properties that get appended to the resulting array from a call to String.prototype.match():

input, index and lastIndex

(MSDN Documentation)

The result is that array comparison fails when using Jasmine's .toEqual() matcher.

I'm still working my way up the learning curve on unit testing, so I'm just curious of what the right way is to do deal with this failure.

The following works but seems a bit lame:

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

Answers


Underscore's 'difference' method can help -

expect(_.difference(['item1', 'item2'], ['item1', 'item2'])).toEqual([]);

http://underscorejs.org/#difference


I think @monkeyboy's answer is not correct.

Since underscore.difference() returns the elements of the first array that are not present in the second array: _.difference([1],[1,2]); is also [] so the test will pass when it shouldn't. I couldn't find a way to solve this using underscore.

So i'm using:

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

which works as expected.

Anyway, i'd like to know how others are doing this.


Need Your Help

Ajax call returns undefined data

javascript c# jquery ajax asp.net-mvc

I have an ajax call that requests data from an MVC controller method.

REG : Custom Dropdown box identification [CAPYBARA]

css ruby xpath cucumber capybara

Looking at selecting a value from the dropdown ( custom ) not regular dropdown , It has a lot of dropdown values