Skip to content

Commit

Permalink
expect no longer tries to equal non-enumerable symbolic properties. F…
Browse files Browse the repository at this point in the history
…ixes jestjs#6392
  • Loading branch information
mweststrate committed Jun 5, 2018
1 parent 241588a commit a34fcb8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
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. ([]())

## 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
6 changes: 5 additions & 1 deletion packages/expect/src/jasmine_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,11 @@ 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(
symbol => Object.getOwnPropertyDescriptor(o, symbol).enumerable,
),
);
})(obj);

if (!isArray) {
Expand Down

0 comments on commit a34fcb8

Please sign in to comment.