Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compare objects with Symbol keys #3437

Merged
merged 2 commits into from
Jun 5, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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);
});
});
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 @@ -213,7 +213,7 @@ function keys(obj, isArray) {
keys.push(key);
}
}
return keys;
return keys.concat(Object.getOwnPropertySymbols(o));
})(obj);

if (!isArray) {
Expand Down