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

feat(expect-expect): support chained function names (#471) #508

Merged
merged 3 commits into from Jan 10, 2020

Conversation

folke
Copy link
Contributor

@folke folke commented Jan 10, 2020

Added support for chained assertion function names and method calls. (see also #471)

This makes it easy to support 3rd party assertion libraries like SuperTest with the option { "assertFunctionNames": ["expect", "request.get.expect"] }

Examples of correct code for deep assertion functions with the
{ "assertFunctionNames": ["expect", "tester.foo.expect"] } option:

/* eslint jest/expect-expect: ["error", { "assertFunctionNames": ["expect", "tester.foo.expect"] }] */
test('nested expect method call', () => {
  class Foo {
    expect(k) {
      return k;
    }
  }
  let tester = {
    foo: function() {
      return new Foo();
    },
  };
  tester.foo().expect(123);
});

Copy link
Collaborator

@G-Rath G-Rath left a comment

Choose a reason for hiding this comment

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

Cheers, thanks for this!

docs/rules/expect-expect.md Outdated Show resolved Hide resolved
@folke folke requested a review from G-Rath January 10, 2020 09:09
Copy link
Collaborator

@G-Rath G-Rath left a comment

Choose a reason for hiding this comment

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

Awesome cheers!

Now you just need to get coverage passing :)

@G-Rath G-Rath merged commit beb1aec into jest-community:master Jan 10, 2020
@G-Rath
Copy link
Collaborator

G-Rath commented Jan 10, 2020

Thanks!

@folke
Copy link
Contributor Author

folke commented Jan 10, 2020

Fixing the coverage turned out to be trickier than expected, since getNodeName will almost never return null

Added (function(){})() as a test case for no-jasmine-globals.

Does the trick :)

@folke
Copy link
Contributor Author

folke commented Jan 10, 2020

Thanks for reviewing and merging in the PR!! ✨

github-actions bot pushed a commit that referenced this pull request Jan 10, 2020
# [23.4.0](v23.3.0...v23.4.0) (2020-01-10)

### Features

* **expect-expect:** support chained function names ([#471](#471)) ([#508](#508)) ([beb1aec](beb1aec))
* **rules:** add support for function declaration as test case ([#504](#504)) ([ac7fa48](ac7fa48))
@github-actions
Copy link

🎉 This PR is included in version 23.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@G-Rath
Copy link
Collaborator

G-Rath commented Jan 10, 2020

Fixing the coverage turned out to be trickier than expected

Interesting - I'll add a note to have a look into this as part of the maintenance run I have planned, just to make sure it's all good :)

Now that you've changed the implementation, it's possible that the overload signature should be tweaked, but regardless your fix here seems to work so that's the main thing :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants