Skip to content

Commit a80b810

Browse files
committed
Fix hasProperty matcher for inherited properties
1 parent 967b335 commit a80b810

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

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

+12
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ describe('getPath()', () => {
7676
});
7777
});
7878

79+
test('property is inherited', () => {
80+
class A {}
81+
A.prototype.a = 'a';
82+
83+
expect(getPath(new A(), 'a')).toEqual({
84+
hasEndProp: true,
85+
lastTraversedObject: new A(),
86+
traversedPath: ['a'],
87+
value: 'a',
88+
});
89+
});
90+
7991
test('path breaks', () => {
8092
expect(getPath({a: {}}, 'a.b.c')).toEqual({
8193
hasEndProp: false,

packages/expect/src/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export const getPath = (
8181
result.traversedPath.unshift(prop);
8282

8383
if (lastProp) {
84-
result.hasEndProp = hasOwnProperty(object, prop);
84+
result.hasEndProp = prop in object;
8585
if (!result.hasEndProp) {
8686
result.traversedPath.shift();
8787
}

0 commit comments

Comments
 (0)