|
| 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 | +}); |
0 commit comments