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

Support asymmetric matching in toMatchObject #2787

Merged
merged 1 commit into from Feb 3, 2017
Merged

Support asymmetric matching in toMatchObject #2787

merged 1 commit into from Feb 3, 2017

Conversation

nfarina
Copy link
Contributor

@nfarina nfarina commented Feb 2, 2017

Closes #2781.

This adds support for “asymmetric matching” to toMatchObject. Example:

const houseForSale = {
  bath: true,
  bedrooms: 4
};

expect(houseForSale).toMatchObject({
  bedrooms: expect.any(Number)
});

Now passes.

@nfarina
Copy link
Contributor Author

nfarina commented Feb 2, 2017

Hm, that doesn't look good - but the CI failure seems to be related to a possibly-intermittent yarn problem. Can the job for the failing Node version be rerun?

@@ -679,6 +679,8 @@ describe('toMatchObject()', () => {
[{a: 'b', t: {x: {r: 'r'}, z: 'z'}}, {t: {x: {r: 'r'}}}],
[{a: [3, 4, 5], b: 'b'}, {a: [3, 4, 5]}],
[{a: [3, 4, 5, 'v'], b: 'b'}, {a: [3, 4, 5, 'v']}],
[{a: 1, c: 2}, {a: jestExpect.any(Number)}],
[{a: {x: 'x', y: 'y'}}, {a: {x: jestExpect.any(String)}}],
Copy link
Collaborator

Choose a reason for hiding this comment

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

yes, tests!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well I do use Jest for a reason ;)

@thymikee
Copy link
Collaborator

thymikee commented Feb 2, 2017

This looks good, thanks for the PR!

@cpojer cpojer merged commit 2571b49 into jestjs:master Feb 3, 2017
@cpojer
Copy link
Member

cpojer commented Feb 3, 2017

Nice work!

@cpojer
Copy link
Member

cpojer commented Feb 3, 2017

I just want to say, this was really good. @nfarina, great first contribution. @thymikee, great work on helping Nick through this. Looking forward to using this in Jest 19 myself!

@nfarina
Copy link
Contributor Author

nfarina commented Feb 3, 2017

Well shucks…it was only four lines of copy-pasted code and @thymikee told me exactly how to do it but I am loving this positive feedback!

@nfarina nfarina deleted the add-asymmetric-tomatchobject branch February 3, 2017 06:32
skovhus pushed a commit to skovhus/jest that referenced this pull request Apr 29, 2017
tushardhole pushed a commit to tushardhole/jest that referenced this pull request Aug 21, 2017
@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 14, 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.

Support expect.any style placeholders in toMatchObject
4 participants