diff --git a/CHANGELOG.md b/CHANGELOG.md index 522e3fbd349e..f77aa582ee69 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## master +### Fixes + +- `[expect]` `toEqual` no longer tries to compare non-enumerable symbolic properties, to be consistent with non-symbolic properties. ([#6398](https://github.com/facebook/jest/pull/6398)) + ## 23.1.0 ### Features diff --git a/packages/expect/src/__tests__/matchers.test.js b/packages/expect/src/__tests__/matchers.test.js index 69e04a4e79b8..08aa419cc767 100644 --- a/packages/expect/src/__tests__/matchers.test.js +++ b/packages/expect/src/__tests__/matchers.test.js @@ -442,6 +442,29 @@ describe('.toEqual()', () => { ); } }); + + test('non-enumerable members should be skipped during equal', () => { + const actual = { + x: 3, + }; + Object.defineProperty(actual, 'test', { + enumerable: false, + value: 5, + }); + expect(actual).toEqual({x: 3}); + }); + + test('non-enumerable symbolic members should be skipped during equal', () => { + const actual = { + x: 3, + }; + const mySymbol = Symbol('test'); + Object.defineProperty(actual, mySymbol, { + enumerable: false, + value: 5, + }); + expect(actual).toEqual({x: 3}); + }); }); describe('.toBeInstanceOf()', () => { diff --git a/packages/expect/src/jasmine_utils.js b/packages/expect/src/jasmine_utils.js index 6fc2f6d2e89f..de423960f58a 100644 --- a/packages/expect/src/jasmine_utils.js +++ b/packages/expect/src/jasmine_utils.js @@ -209,7 +209,12 @@ function keys(obj, isArray, hasKey) { keys.push(key); } } - return keys.concat((Object.getOwnPropertySymbols(o): Array)); + return keys.concat( + (Object.getOwnPropertySymbols(o): Array).filter( + //$FlowFixMe Jest complains about nullability, but we know for sure that property 'symbol' does exist. + symbol => Object.getOwnPropertyDescriptor(o, symbol).enumerable, + ), + ); })(obj); if (!isArray) {