jasmine: 2.5.0 Regression issue with expect().toHaveBeenCalledWith()

After installing 2.5.0, many of our tests are failing with:

PhantomJS 2.1.1 (Windows 8 0.0.0) Some test... FAILED
        TypeError: undefined is not a constructor (evaluating 'allKeys[i].match(/^[0-9]+$/)') in C:/<path>/node_modules/jasmine-core/lib/jasmine-core/jasmine.js (line 2988)
        c:/<path>/specFile.js:79:85

All the tests I’ve looked at so far call toHaveBeenCalledWith, e.g.:

expect(aSpy).toHaveBeenCalledWith({
  someProperties: "string",
  someOtherProperties: true
})

The full function that is throwing an error is:

    function keys(obj, isArray) {
      var allKeys = Object.keys ? Object.keys(obj) :
        (function(o) {
            var keys = [];
            for (var key in o) {
                if (has(o, key)) {
                    keys.push(key);
                }
            }
            return keys;
        })(obj);

      if (!isArray) {
        return allKeys;
      }

      var extraKeys = [];
      for (var i in allKeys) {
        if (!allKeys[i].match(/^[0-9]+$/)) {
          extraKeys.push(allKeys[i]);
        }
      }

      return extraKeys;
    }

(edit)

Temporary Workaround

Lock jasmine-core to version 2.4.1 until this is addressed.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 15
  • Comments: 16 (2 by maintainers)

Commits related to this issue

Most upvoted comments

Same here. The folllowing test fails:

it('should equal', function() {
  expect(true).toEqual(true); // ok
  expect([true]).toEqual([true]); // fail
}

Fails with

PhantomJS 1.9.8 (Windows 8 0.0.0) This should equal FAILED
        TypeError: 'undefined' is not a function (evaluating 'allKeys[i].match(/^[0-9]+$/)')
            at D:/toEqualSpec.js:7

The fix should be released in v2.5.1