Skip to content

Commit

Permalink
expect: Revert change to distinguish undefined value from no property (
Browse files Browse the repository at this point in the history
…#8067)

* expect: Revert change to distinguish undefined value from no property

* Update CHANGELOG.md
  • Loading branch information
pedrottimark authored and mjesun committed Mar 6, 2019
1 parent 547dcea commit f2af727
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 0 additions & 13 deletions packages/expect/src/__tests__/__snapshots__/matchers.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2997,19 +2997,6 @@ Difference:
Comparing two different types of values. Expected <green>undefined</> but received <red>number</>."
`;

exports[`.toHaveProperty() {pass: false} expect({"a": {}}).toHaveProperty('a.b', undefined) 1`] = `
"<dim>expect(</><red>object</><dim>).toHaveProperty(</><green>path</><dim>, </><green>value</><dim>)</>

Expected the object:
<red>{\\"a\\": {}}</>
To have a nested property:
<green>\\"a.b\\"</>
With a value of:
<green>undefined</>
Received:
<red>object</>.a: <red>{}</>"
`;

exports[`.toHaveProperty() {pass: false} expect({"a": 1}).toHaveProperty('a.b.c.d') 1`] = `
"<dim>expect(</><red>object</><dim>).toHaveProperty(</><green>path</><dim>)</>

Expand Down
2 changes: 1 addition & 1 deletion packages/expect/src/__tests__/matchers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions packages/expect/src/matchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('.');

Expand Down

0 comments on commit f2af727

Please sign in to comment.