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

[unbound-method] Allow passing unbound methods to matchers when method isn't called #985

Open
adalinesimonian opened this issue Nov 13, 2021 · 1 comment

Comments

@adalinesimonian
Copy link

jest/unbound-method currently returns a problem for:

import getMethod from './get-method'

const obj = {
  method: jest.fn(),
}

it('should get a method', () => {
  expect(getMethod(obj)).toBe(obj.method) // problem here: Avoid referencing unbound methods…
})

I think it'd make sense to allow passing methods to matchers to check for references in cases where the method isn't being called.

@G-Rath G-Rath changed the title Allow passing unbound methods to matchers when method isn't called [unbound-method] Allow passing unbound methods to matchers when method isn't called Dec 19, 2021
@G-Rath
Copy link
Collaborator

G-Rath commented Jun 4, 2022

The problem is there's no way for us to know if a general matcher will call that argument or not - we could ship a list of all Jest matchers to at least special case them, but I'm a bit reluctant to do that as it would make us less consistent with the base rule (since that has the same issue).

We could do it for just a few of the matchers (like the equality ones) but I feel like this isn't a common enough pattern to be worth the inconsistency.

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

No branches or pull requests

2 participants