diff --git a/CHANGELOG.md b/CHANGELOG.md index 746190c9c92b..b35aa33644df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ - `[expect]` Remove duck typing and obsolete browser support code when comparing DOM nodes and use DOM-Level-3 API instead ([#7995](https://github.com/facebook/jest/pull/7995)) - `[jest-mock]` Adds a type check to `prototype` to allow mocks of objects with a primitive `prototype` property. ([#8040](https://github.com/facebook/jest/pull/8040)) - `[jest-util]`Make sure to not fail if unable to assign `toStringTag` to the `process` object, which is read only in Node 12 ([#8050](https://github.com/facebook/jest/pull/8050)) +- `[expect]` Revert change to distinguish undefined value from no property ([#8067](https://github.com/facebook/jest/pull/8067)) ### Chore & Maintenance diff --git a/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap b/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap index beea9f37fb31..42237ee166b2 100644 --- a/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap +++ b/packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap @@ -2997,19 +2997,6 @@ Difference: Comparing two different types of values. Expected undefined but received number." `; -exports[`.toHaveProperty() {pass: false} expect({"a": {}}).toHaveProperty('a.b', undefined) 1`] = ` -"expect(object).toHaveProperty(path, value) - -Expected the object: - {\\"a\\": {}} -To have a nested property: - \\"a.b\\" -With a value of: - undefined -Received: - object.a: {}" -`; - exports[`.toHaveProperty() {pass: false} expect({"a": 1}).toHaveProperty('a.b.c.d') 1`] = ` "expect(object).toHaveProperty(path) diff --git a/packages/expect/src/__tests__/matchers.test.js b/packages/expect/src/__tests__/matchers.test.js index 8f79c49c15c4..dc31c645f5d9 100644 --- a/packages/expect/src/__tests__/matchers.test.js +++ b/packages/expect/src/__tests__/matchers.test.js @@ -1355,7 +1355,7 @@ describe('.toHaveProperty()', () => { [{a: {b: {c: 5}}}, 'a.b', {c: 4}], [new Foo(), 'a', 'a'], [new Foo(), 'b', undefined], - [{a: {}}, 'a.b', undefined], + // [{a: {}}, 'a.b', undefined], // wait until Jest 25 ].forEach(([obj, keyPath, value]) => { test(`{pass: false} expect(${stringify( obj, diff --git a/packages/expect/src/matchers.ts b/packages/expect/src/matchers.ts index 7adb37cb497f..bad0f0424f36 100644 --- a/packages/expect/src/matchers.ts +++ b/packages/expect/src/matchers.ts @@ -633,9 +633,9 @@ const matchers: MatchersObject = { const result = getPath(object, keyPath); const {lastTraversedObject, hasEndProp} = result; - const pass = - hasEndProp && - (!valuePassed || equals(result.value, value, [iterableEquality])); + const pass = valuePassed + ? equals(result.value, value, [iterableEquality]) + : hasEndProp; const traversedPath = result.traversedPath.join('.');