From 878d01727fa91736bf8520491b82714a99b68204 Mon Sep 17 00:00:00 2001 From: Cristian Penarrieta Date: Tue, 2 May 2017 13:36:03 -0700 Subject: [PATCH 1/2] compare objects with Symbol keys --- .../src/__tests__/symbol-in-objects-test.js | 44 +++++++++++++++++++ packages/jest-matchers/src/jasmine-utils.js | 2 +- 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 packages/jest-matchers/src/__tests__/symbol-in-objects-test.js diff --git a/packages/jest-matchers/src/__tests__/symbol-in-objects-test.js b/packages/jest-matchers/src/__tests__/symbol-in-objects-test.js new file mode 100644 index 000000000000..1c9d212ed088 --- /dev/null +++ b/packages/jest-matchers/src/__tests__/symbol-in-objects-test.js @@ -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 mixes 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); + }); +}); diff --git a/packages/jest-matchers/src/jasmine-utils.js b/packages/jest-matchers/src/jasmine-utils.js index 45101f5ea09a..11059efd639d 100644 --- a/packages/jest-matchers/src/jasmine-utils.js +++ b/packages/jest-matchers/src/jasmine-utils.js @@ -213,7 +213,7 @@ function keys(obj, isArray) { keys.push(key); } } - return keys; + return keys.concat(Object.getOwnPropertySymbols(o)); })(obj); if (!isArray) { From cba3319a3d64f1aaae99fcb90162fc66f0bf6e68 Mon Sep 17 00:00:00 2001 From: Christoph Pojer Date: Mon, 5 Jun 2017 09:25:01 +0100 Subject: [PATCH 2/2] Update symbol-in-objects-test.js --- packages/jest-matchers/src/__tests__/symbol-in-objects-test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jest-matchers/src/__tests__/symbol-in-objects-test.js b/packages/jest-matchers/src/__tests__/symbol-in-objects-test.js index 1c9d212ed088..3b247f991346 100644 --- a/packages/jest-matchers/src/__tests__/symbol-in-objects-test.js +++ b/packages/jest-matchers/src/__tests__/symbol-in-objects-test.js @@ -21,7 +21,7 @@ describe('Symbol in objects', () => { expect(obj1).not.toEqual(obj2); }); - test('should compare objects with mixes keys and Symbol', () => { + 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'};