Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
23 changes: 23 additions & 0 deletions packages/expect/src/__tests__/matchers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()', () => {
Expand Down
7 changes: 6 additions & 1 deletion packages/expect/src/jasmine_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,12 @@ function keys(obj, isArray, hasKey) {
keys.push(key);
}
}
return keys.concat((Object.getOwnPropertySymbols(o): Array<any>));
return keys.concat(
(Object.getOwnPropertySymbols(o): Array<any>).filter(
//$FlowFixMe Jest complains about nullability, but we know for sure that property 'symbol' does exist.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably mistyped in Flow libdefs. Would be great to send them a PR with a fix, but I have never done it yet, so I won't recommend anything 😅 cc @cpojer who is Flow expert recently ;)

symbol => Object.getOwnPropertyDescriptor(o, symbol).enumerable,
),
);
})(obj);

if (!isArray) {
Expand Down