-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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 variadic custom asymmetric matchers #6898
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed. If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks! |
Codecov Report
@@ Coverage Diff @@
## master #6898 +/- ##
==========================================
+ Coverage 66.98% 66.98% +<.01%
==========================================
Files 250 250
Lines 10358 10360 +2
Branches 4 3 -1
==========================================
+ Hits 6938 6940 +2
Misses 3419 3419
Partials 1 1
Continue to review full report at Codecov.
|
|
||
constructor(sample: any, inverse: boolean = false) { | ||
constructor(inverse: boolean = false, ...sample: any[]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sample
will likely want renaming, maybe to received
or something more suitable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed!
deploy/netlify is currently failing, but that seems to be the case for a few other Pull Requests as well. I don't think the failure is caused by this PR(?) |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it!
Mind updating the docs and changelog at the same time?
@@ -12,23 +12,22 @@ const {equals} = require('../jasmine_utils'); | |||
const jestExpect = require('../'); | |||
|
|||
jestExpect.extend({ | |||
toBeDivisibleBy(actual, expected) { | |||
const pass = actual % expected === 0; | |||
toBeWithinRange(actual, floor, ceiling) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just add it in addition to the other one?
@@ -59,9 +59,9 @@ export const setMatchers = ( | |||
// expect is defined | |||
|
|||
class CustomMatcher extends AsymmetricMatcher { | |||
sample: any; | |||
sample: any[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Array<any>
|
||
constructor(sample: any, inverse: boolean = false) { | ||
constructor(inverse: boolean = false, ...sample: any[]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed!
@@ -85,15 +85,16 @@ export const setMatchers = ( | |||
} | |||
|
|||
toAsymmetricMatcher() { | |||
return `${this.toString()}<${this.sample}>`; | |||
return `${this.toString()}<${this.sample.join(',')}>`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe join(', ')
instead?
And yes, the netifly deploy is broken for most PRs, not sure why 🙁 |
@aymericbouzy thoughts on this? 🙂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside from @SimenB remarks, looks good!
Great points @SimenB, thanks. I'll push an amended commit soon. |
@SimenB for the docs update, should I amend https://github.com/facebook/jest/blob/v23.5.0/docs/ExpectAPI.md#expectextendmatchers in /docs/ExpectAPI.md to use |
FYI, I'm receiving this failing test output locally. The failures are a long distance from my changes and pass in CI. I've dismissed them as environmental but let me know if I need to address anything. Collapsed Jest Output
|
Those fail locally for me as well, I wonder if it's something to do with mac vs linux (hidden files, casing in file names... something like that) |
Replacing the example (and stating that it supports variadic args) seems sensible as the doc update, yeah 🙂 |
I like it too! I didn't know about custom variadic matchers when I created custom asymmetric matchers, it obviously makes total sense. Maybe when documenting this new feature, we should first document how to create a variadic symmetric custom matcher? |
Thanks @aymericbouzy, please check the docs amend above and let me know if anything more can be done to make this clearer. |
Now the netlify deploy passed... Does the deploy fail when there are no docs changes? @endiliey |
@SimenB I'm also wondering about that. But the failure has always been the same, something about However, if I go to netlify itself to retry deploy & clear build cache it will then succeed On another note, I've sent you & @rickhanlonii an invite for the jest netlify admin. I couldn't find @thymikee email 😂. We should've done this from the beginning, sorry for not noticing this earlier 😃 |
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. |
Refs #5503
Summary
expect.extend
allows users to add their own custom matchers, with an asymmetric equivalent being made at the same time. Variadic Matchers are supported, but not variadic asymmetric matchers. This PR hopes to help move us closer to supporting that.This enables community matchers such as those in expect-more-jest.
Test plan
I have updated the existing tests created in #5503 to be an example of a variadic asymmetric matcher, checked the changed snapshots are correct, and then updated them.