Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Support class instances in .toHaveProperty() matcher #5367

Merged
merged 2 commits into from
Jan 22, 2018

Conversation

thymikee
Copy link
Collaborator

Summary

Checking for object own property with Object.prototype.hasOwnProperty.call(object, value) won't work on class instance getters. To support that, we can fall back to checking object.constructor.prototype, because we know object is an Object so we can actually get its class prototype which stores the getter.

Also refactored the code a bit for perf (remove unnecessary delete) and readability (flattened if/else branching, use ?w=1 to review)

Resolves #5339

Test plan

Added a test or two.

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A, nice!

Missing changelog entry, otherwise no comments (pending CI)

@codecov-io
Copy link

codecov-io commented Jan 22, 2018

Codecov Report

Merging #5367 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #5367   +/-   ##
=======================================
  Coverage   61.33%   61.33%           
=======================================
  Files         205      205           
  Lines        6924     6924           
  Branches        4        3    -1     
=======================================
  Hits         4247     4247           
  Misses       2676     2676           
  Partials        1        1

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 139f976...00c2d2f. Read the comment docs.


### Fixes

* `[jest]` Add `import-local` to `jest` package.
([#5353](https://github.com/facebook/jest/pull/5353))
* `[expect]` Support class instances in `.toHaveProperty()` matcher.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also affected .toMatchObject() as far as I can tell.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in a good or bad way?

Copy link
Contributor

@eps1lon eps1lon Mar 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a very good way. It basically enables .toMatchObject() to check if a given class implements an interface.

But in my opinion this should be included in the changelog regardless of whether one finds the change good or bad.

Copy link
Member

@SimenB SimenB Mar 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was more in the vein of "is this a regression we have to fix or not?". Good that it's not!

PR welcome to expand the changelog entry 🙂

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I include some tests just to make sure I identified that behavior correctly?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be awesome!

eps1lon added a commit to eps1lon/poe-mods that referenced this pull request Mar 2, 2018
- jestjs/jest#5367 added support for "interface" matching with getters
cpojer pushed a commit that referenced this pull request Mar 4, 2018
@thymikee thymikee deleted the fix/to-have-property-class-instance branch March 16, 2019 10:56
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

toHaveProperty does not match properties coming from class instance getters
6 participants