Skip to content
New issue

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

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

Already on GitHub? # to your account

[expect-expect]: Unable to allow methods in assertFunctionNames #175

Closed
randycoulman opened this issue Oct 12, 2018 · 3 comments
Closed

Comments

@randycoulman
Copy link

In testing the expect-expect rule on one of my projects, I found that it was reporting a number of tests that didn't have expect calls. In these tests, I was using td.verify from testdouble.js which verifies that a particular test double was called.

I attempted to use the assertFunctionNames option to configure td.verify as a known expect function, but was unable to get it to work. The tests in questions were still reported as violating this rule.

I tried both assertFunctionNames: ["expect", "td.verify"] and assertFunctionNames: ["expect", "verify"] and neither approach worked.

I was able to work around the issue by doing the following, but this is not the normal way to use testdouble.js and I'd prefer not to have to do it everywhere I use td.verify.

const { verify } = td;

test("...", () => {
  // ...
  verify(someFunctionCall());
}

I think the more general problem here is that the rule is not able to match anything but bare functions; it can't handle methods on an object.

I don't know the AST syntax well enough to know how to fix this, but I thought I'd at least report it here in the hope that someone more familiar can take care of it.

@macklinu
Copy link
Collaborator

Thanks for reporting this issue with clear steps and a use case. It'd be good to consider a call expression with an object and property (like td.verify). 👍 PRs welcome from anyone, will try to take a look at this this weekend as well. 😄

randycoulman added a commit to CodingZeal/eslint-config-zeal that referenced this issue Oct 12, 2018
- New rule: `jest/expect-expect` defaults to `off` for now, as we are unable to configure it to recognize `td.verify` as an assertion method.  See jest-community/eslint-plugin-jest#175.
- New rule: `jest/no-alias-methods` defaults to `off` because we prefer `toThrowError` over `toThrow` and there's no way to configure the rule to allow some aliases but not all.
- New rule: `jest/no-test-return-statement` defaults to `warn`
- New rule: `jest/prefer-inline-snapshots` defaults to `off`
- New rule: `jest/prefer-strict-equal` defaults to `warn`
- New rule: `jest/require-tothrow-message` defaults to `warn`
@macklinu
Copy link
Collaborator

I can push up a PR for this shortly.

@SimenB
Copy link
Member

SimenB commented Oct 14, 2018

🎉 This issue has been resolved in version 21.24.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

3 participants