-
Notifications
You must be signed in to change notification settings - Fork 237
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
New rule proposal, prefer mockReturnValue over mockImplementation #1674
Comments
I'm not sure about this - while it seems straightforward in theory, in practice I'm not sure it could ever be safe:
The only time we could safely cover this would be for the literal case, which you should be able to cover with |
If the rule only supported literals that'd be good. Ideal is if we can have it detect a reference of a literal via a |
oh duh yea course, we should be able to check that to know about mutability 🤦 so yeah some kind of |
Good point about I've even seen people write this: example.mockImplementation(() => Promise.resolve(1)); Instead of just: example.mockResolvedValue(1); |
Note that there is a slight difference in those which will be important to call out: the first creates an actual native That's generally very rare as while not outright bad, |
We are seeing examples likes this
Rather than just
This seems to be a sound change to make when
value
is a literal primitive e.g.true
const
primitive valueIn more complex values using
mockImplementation
may be approprate, e.g. the result is deferred or closures a var etcThe text was updated successfully, but these errors were encountered: