toEqual does not compare symbols that cannot be enumerated
This commit is contained in:
@@ -5589,8 +5589,15 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
|||||||
keys.push(key);
|
keys.push(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line compat/compat
|
|
||||||
return keys.concat(Object.getOwnPropertySymbols(o));
|
var symbols = Object.getOwnPropertySymbols(o);
|
||||||
|
for (var i = 0; i < symbols.length; i++) {
|
||||||
|
if (o.propertyIsEnumerable(symbols[i])) {
|
||||||
|
keys.push(symbols[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return keys;
|
||||||
})(obj);
|
})(obj);
|
||||||
|
|
||||||
if (!isArray) {
|
if (!isArray) {
|
||||||
|
|||||||
@@ -1042,6 +1042,29 @@ describe('toEqual', function() {
|
|||||||
// == Symbols ==
|
// == Symbols ==
|
||||||
|
|
||||||
describe('Symbols', function() {
|
describe('Symbols', function() {
|
||||||
|
it('Enumerable symbols are compared', function() {
|
||||||
|
const sym = Symbol('foo');
|
||||||
|
const actual = {};
|
||||||
|
Object.defineProperty(actual, sym, {
|
||||||
|
value: '',
|
||||||
|
enumerable: true
|
||||||
|
});
|
||||||
|
const expected = { [sym]: '' };
|
||||||
|
|
||||||
|
expect(actual).toEqual(expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Symbols that cannot be enumerated are not compared ', function() {
|
||||||
|
const sym = Symbol('foo');
|
||||||
|
const actual = {};
|
||||||
|
Object.defineProperty(actual, sym, {
|
||||||
|
value: '',
|
||||||
|
enumerable: false
|
||||||
|
});
|
||||||
|
const expected = {};
|
||||||
|
expect(actual).toEqual(expected);
|
||||||
|
});
|
||||||
|
|
||||||
it('Fails if Symbol compared to Object', function() {
|
it('Fails if Symbol compared to Object', function() {
|
||||||
const sym = Symbol('foo');
|
const sym = Symbol('foo');
|
||||||
const obj = {};
|
const obj = {};
|
||||||
|
|||||||
@@ -532,8 +532,15 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
|||||||
keys.push(key);
|
keys.push(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line compat/compat
|
|
||||||
return keys.concat(Object.getOwnPropertySymbols(o));
|
var symbols = Object.getOwnPropertySymbols(o);
|
||||||
|
for (var i = 0; i < symbols.length; i++) {
|
||||||
|
if (o.propertyIsEnumerable(symbols[i])) {
|
||||||
|
keys.push(symbols[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return keys;
|
||||||
})(obj);
|
})(obj);
|
||||||
|
|
||||||
if (!isArray) {
|
if (!isArray) {
|
||||||
|
|||||||
Reference in New Issue
Block a user