[go: up one dir, main page]

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 variadic custom asymmetric matchers #6898

Merged
merged 1 commit into from
Aug 29, 2018
Merged

fix: support variadic custom asymmetric matchers #6898

merged 1 commit into from
Aug 29, 2018

Conversation

JamieMason
Copy link
Contributor
@JamieMason JamieMason commented Aug 27, 2018

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.

@facebook-github-bot
Copy link
Contributor

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-io
Copy link
codecov-io commented Aug 27, 2018

Codecov Report

Merging #6898 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
packages/expect/src/jest_matchers_object.js 85.71% <100%> (+1.09%) ⬆️

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 a19cad6...ba35d72. Read the comment docs.


constructor(sample: any, inverse: boolean = false) {
constructor(inverse: boolean = false, ...sample: any[]) {
Copy link
Contributor Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

agreed!

@JamieMason
Copy link
Contributor Author

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(?)

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

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.

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) {
Copy link
Member

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[];
Copy link
Member

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[]) {
Copy link
Member

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(',')}>`;
Copy link
Member

Choose a reason for hiding this comment

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

maybe join(', ') instead?

@SimenB
Copy link
Member
SimenB commented Aug 28, 2018

And yes, the netifly deploy is broken for most PRs, not sure why 🙁

@SimenB
Copy link
Member
SimenB commented Aug 28, 2018

@aymericbouzy thoughts on this? 🙂

Copy link
Collaborator
@thymikee thymikee left a 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!

@JamieMason
Copy link
Contributor Author

Great points @SimenB, thanks. I'll push an amended commit soon.

@JamieMason
Copy link
Contributor Author

@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 toBeWithinRange as the example? Or would another approach be better? Thanks.

@JamieMason
Copy link
Contributor Author

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
Summary of all failing tests
 FAIL  packages/jest-cli/src/__tests__/SearchSource.test.js
  ● SearchSource › testPathsMatching › finds tests matching a pattern via testRegex

    expect(received).toEqual(expected)

    Expected value to equal:
      [".hiddenFolder/not-really-a-test.txt", "__testtests__/not-really-a-test.txt"]
    Received:
      ["__testtests__/not-really-a-test.txt"]

    Difference:

    - Expected
    + Received

      Array [
    -   ".hiddenFolder/not-really-a-test.txt",
        "__testtests__/not-really-a-test.txt",
      ]

      at findMatchingTests.then.data (packages/jest-cli/src/__tests__/SearchSource.test.js:123:26)

  ● SearchSource › testPathsMatching › finds tests matching a pattern via testMatch

    expect(received).toEqual(expected)

    Expected value to equal:
      [".hiddenFolder/not-really-a-test.txt", "__testtests__/not-really-a-test.txt"]
    Received:
      ["__testtests__/not-really-a-test.txt"]

    Difference:

    - Expected
    + Received

      Array [
    -   ".hiddenFolder/not-really-a-test.txt",
        "__testtests__/not-really-a-test.txt",
      ]

      at findMatchingTests.then.data (packages/jest-cli/src/__tests__/SearchSource.test.js:147:26)

@SimenB
Copy link
Member
SimenB commented Aug 28, 2018

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)

@SimenB
Copy link
Member
SimenB commented Aug 28, 2018

Replacing the example (and stating that it supports variadic args) seems sensible as the doc update, yeah 🙂

@aymericbouzy
Copy link
Contributor

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?

@JamieMason
Copy link
Contributor Author

Thanks @aymericbouzy, please check the docs amend above and let me know if anything more can be done to make this clearer.

@SimenB
Copy link
Member
SimenB commented Aug 28, 2018

Now the netlify deploy passed... Does the deploy fail when there are no docs changes? @endiliey

@endiliey
Copy link
Contributor
endiliey commented Aug 28, 2018

@SimenB I'm also wondering about that. But the failure has always been the same, something about failing to prepare repo. It hasn't even entered any docusaurus specific command

However, if I go to netlify itself to retry deploy & clear build cache it will then succeed

image

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 😃

@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 12, 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.

7 participants