Fixed exception when comparing arrays with Symbol keys

* Fixes #1966
This commit is contained in:
Steve Gravrock
2022-05-07 10:42:29 -07:00
parent 270344bd38
commit 9d80377fe3
3 changed files with 24 additions and 2 deletions

View File

@@ -5603,7 +5603,7 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
var extraKeys = [];
for (var i = 0; i < allKeys.length; i++) {
if (!/^[0-9]+$/.test(allKeys[i])) {
if (typeof allKeys[i] === 'symbol' || !/^[0-9]+$/.test(allKeys[i])) {
extraKeys.push(allKeys[i]);
}
}

View File

@@ -125,6 +125,28 @@ describe('matchersUtil', function() {
expect(matchersUtil.equals(one, two)).toBe(true);
});
it('handles symbol keys in Arrays', function() {
const matchersUtil = new jasmineUnderTest.MatchersUtil(),
sym = Symbol('foo'),
arr1 = [];
let arr2 = [];
arr1[sym] = 'bar';
arr2[sym] = 'bar';
expect(matchersUtil.equals(arr1, arr2)).toBe(true);
arr2[sym] = 'baz';
expect(matchersUtil.equals(arr1, arr2)).toBe(false);
arr2 = [];
arr2[Symbol('foo')] = 'bar';
expect(matchersUtil.equals(arr1, arr2)).toBe(false);
arr2 = [];
arr2['foo'] = 'bar';
expect(matchersUtil.equals(arr1, arr2)).toBe(false);
});
it('passes for Errors that are the same type and have the same message', function() {
const matchersUtil = new jasmineUnderTest.MatchersUtil();
expect(matchersUtil.equals(new Error('foo'), new Error('foo'))).toBe(

View File

@@ -546,7 +546,7 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
var extraKeys = [];
for (var i = 0; i < allKeys.length; i++) {
if (!/^[0-9]+$/.test(allKeys[i])) {
if (typeof allKeys[i] === 'symbol' || !/^[0-9]+$/.test(allKeys[i])) {
extraKeys.push(allKeys[i]);
}
}