Skip to content

Commit

Permalink
compare objects with Symbol keys (jestjs#3437)
Browse files Browse the repository at this point in the history
* compare objects with Symbol keys

* Update symbol-in-objects-test.js
  • Loading branch information
cpenarrieta authored and cpojer committed Jun 5, 2017
1 parent e4ad481 commit bade6b0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
44 changes: 44 additions & 0 deletions packages/jest-matchers/src/__tests__/symbol-in-objects-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @emails oncall+jsinfra
*/

'use strict';

describe('Symbol in objects', () => {
test('should compare objects with Symbol keys', () => {
const sym = Symbol('foo');
const obj1 = {[sym]: 'one'};
const obj2 = {[sym]: 'two'};
const obj3 = {[sym]: 'one'};

expect(obj1).toEqual(obj3);
expect(obj1).not.toEqual(obj2);
});

test('should compare objects with mixed keys and Symbol', () => {
const sym = Symbol('foo2');
const obj1 = {foo: 2, [sym]: 'one'};
const obj2 = {foo: 2, [sym]: 'two'};
const obj3 = {foo: 2, [sym]: 'one'};

expect(obj1).toEqual(obj3);
expect(obj1).not.toEqual(obj2);
});

test('should compare objects with different Symbol keys', () => {
const sym = Symbol('foo');
const sym2 = Symbol('foo');
const obj1 = {[sym]: 'one'};
const obj2 = {[sym2]: 'one'};
const obj3 = {[sym]: 'one'};

expect(obj1).toEqual(obj3);
expect(obj1).not.toEqual(obj2);
});
});
2 changes: 1 addition & 1 deletion packages/jest-matchers/src/jasmine-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ function keys(obj, isArray) {
keys.push(key);
}
}
return keys;
return keys.concat(Object.getOwnPropertySymbols(o));
})(obj);

if (!isArray) {
Expand Down

0 comments on commit bade6b0

Please sign in to comment.