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

New Rule: Prefer mock resolved/rejected shorthands #104

Closed
alexilyaev opened this issue Apr 8, 2018 · 3 comments · Fixed by #1167
Closed

New Rule: Prefer mock resolved/rejected shorthands #104

alexilyaev opened this issue Apr 8, 2018 · 3 comments · Fixed by #1167

Comments

@alexilyaev
Copy link

Simple sugar function for:

jest.fn().mockReturnValue(Promise.resolve(value));

Useful to mock async functions in async tests:

test('async test', async () => {
  const asyncMock = jest.fn().mockResolvedValue(43);

  await asyncMock(); // 43
});

Refs:

@SimenB
Copy link
Member

SimenB commented Apr 9, 2018

Yeah, sounds good!

@G-Rath
Copy link
Collaborator

G-Rath commented May 29, 2022

fwiw this is actually technically not the same due to jestjs/jest#6645 but I still think it's worth a rule with a fixer to start with, and turn it into a suggestion if we get complaints.

(I've so far only hit this once (slorber/react-async-hook#24) so am hoping it's very rare).

@github-actions
Copy link

🎉 This issue has been resolved in version 26.7.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging a pull request may close this issue.

3 participants