Skip to content

Commit bade6b0

Browse files
cpenarrietacpojer
authored andcommitted
compare objects with Symbol keys (jestjs#3437)
* compare objects with Symbol keys * Update symbol-in-objects-test.js
1 parent e4ad481 commit bade6b0

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
3+
*
4+
* This source code is licensed under the BSD-style license found in the
5+
* LICENSE file in the root directory of this source tree. An additional grant
6+
* of patent rights can be found in the PATENTS file in the same directory.
7+
*
8+
* @emails oncall+jsinfra
9+
*/
10+
11+
'use strict';
12+
13+
describe('Symbol in objects', () => {
14+
test('should compare objects with Symbol keys', () => {
15+
const sym = Symbol('foo');
16+
const obj1 = {[sym]: 'one'};
17+
const obj2 = {[sym]: 'two'};
18+
const obj3 = {[sym]: 'one'};
19+
20+
expect(obj1).toEqual(obj3);
21+
expect(obj1).not.toEqual(obj2);
22+
});
23+
24+
test('should compare objects with mixed keys and Symbol', () => {
25+
const sym = Symbol('foo2');
26+
const obj1 = {foo: 2, [sym]: 'one'};
27+
const obj2 = {foo: 2, [sym]: 'two'};
28+
const obj3 = {foo: 2, [sym]: 'one'};
29+
30+
expect(obj1).toEqual(obj3);
31+
expect(obj1).not.toEqual(obj2);
32+
});
33+
34+
test('should compare objects with different Symbol keys', () => {
35+
const sym = Symbol('foo');
36+
const sym2 = Symbol('foo');
37+
const obj1 = {[sym]: 'one'};
38+
const obj2 = {[sym2]: 'one'};
39+
const obj3 = {[sym]: 'one'};
40+
41+
expect(obj1).toEqual(obj3);
42+
expect(obj1).not.toEqual(obj2);
43+
});
44+
});

packages/jest-matchers/src/jasmine-utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ function keys(obj, isArray) {
215215
keys.push(key);
216216
}
217217
}
218-
return keys;
218+
return keys.concat(Object.getOwnPropertySymbols(o));
219219
})(obj);
220220

221221
if (!isArray) {

0 commit comments

Comments
 (0)