Skip to content

Commit e82a933

Browse files
mweststratecpojer
authored andcommitted
Fix: expect no longer tries to equal non-enumerable symbolic properties.… (#6398)
* `expect` no longer tries to equal non-enumerable symbolic properties. Fixes #6392 * Updated changelog with PR number * Fixed linting errors * 'fixed' jest error
1 parent 241588a commit e82a933

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## master
22

3+
### Fixes
4+
5+
- `[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))
6+
37
## 23.1.0
48

59
### Features

packages/expect/src/__tests__/matchers.test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,29 @@ describe('.toEqual()', () => {
442442
);
443443
}
444444
});
445+
446+
test('non-enumerable members should be skipped during equal', () => {
447+
const actual = {
448+
x: 3,
449+
};
450+
Object.defineProperty(actual, 'test', {
451+
enumerable: false,
452+
value: 5,
453+
});
454+
expect(actual).toEqual({x: 3});
455+
});
456+
457+
test('non-enumerable symbolic members should be skipped during equal', () => {
458+
const actual = {
459+
x: 3,
460+
};
461+
const mySymbol = Symbol('test');
462+
Object.defineProperty(actual, mySymbol, {
463+
enumerable: false,
464+
value: 5,
465+
});
466+
expect(actual).toEqual({x: 3});
467+
});
445468
});
446469

447470
describe('.toBeInstanceOf()', () => {

packages/expect/src/jasmine_utils.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,12 @@ function keys(obj, isArray, hasKey) {
209209
keys.push(key);
210210
}
211211
}
212-
return keys.concat((Object.getOwnPropertySymbols(o): Array<any>));
212+
return keys.concat(
213+
(Object.getOwnPropertySymbols(o): Array<any>).filter(
214+
//$FlowFixMe Jest complains about nullability, but we know for sure that property 'symbol' does exist.
215+
symbol => Object.getOwnPropertyDescriptor(o, symbol).enumerable,
216+
),
217+
);
213218
})(obj);
214219

215220
if (!isArray) {

0 commit comments

Comments
 (0)