Skip to content

Commit

Permalink
Fix toHaveProperty matcher for inherited properties
Browse files Browse the repository at this point in the history
  • Loading branch information
rubennorte committed Jan 23, 2019
1 parent 967b335 commit e0719ad
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@

### Fixes

- `[expect]` Accept inherited properties in `toHaveProperty` matcher ([#7686](https://github.com/facebook/jest/pull/7686))
- `[jest-diff]` Do not claim that `-0` and `0` have no visual difference ([#7605](https://github.com/facebook/jest/pull/7605))
- `[jest-mock]` Fix automock for numeric function names ([#7653](https://github.com/facebook/jest/pull/7653))
- `[jest-config]` Ensure `existsSync` is only called with a string parameter ([#7607](https://github.com/facebook/jest/pull/7607))
Expand Down
12 changes: 12 additions & 0 deletions packages/expect/src/__tests__/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ describe('getPath()', () => {
});
});

test('property is inherited', () => {
class A {}
A.prototype.a = 'a';

expect(getPath(new A(), 'a')).toEqual({
hasEndProp: true,
lastTraversedObject: new A(),
traversedPath: ['a'],
value: 'a',
});
});

test('path breaks', () => {
expect(getPath({a: {}}, 'a.b.c')).toEqual({
hasEndProp: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/expect/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const getPath = (
result.traversedPath.unshift(prop);

if (lastProp) {
result.hasEndProp = hasOwnProperty(object, prop);
result.hasEndProp = prop in object;
if (!result.hasEndProp) {
result.traversedPath.shift();
}
Expand Down

0 comments on commit e0719ad

Please sign in to comment.