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

[valid-expect-in-promise] Error is reported even though promise is awaited #930

Closed
srmagura opened this issue Oct 10, 2021 · 2 comments · Fixed by #936
Closed

[valid-expect-in-promise] Error is reported even though promise is awaited #930

srmagura opened this issue Oct 10, 2021 · 2 comments · Fixed by #936

Comments

@srmagura
Copy link

Minimal repro

This code

it("handles an error", async () => {
  const p = Promise.reject(new Error("test error")).then(undefined, (e) => {
    expect(e).toBeInstanceOf(Error);
    return "handled";
  });

  expect(await p).toBe("handled");
});

produces the error

This promise should either be returned or awaited to ensure the expects in it's chain are called  jest/valid-expect-in-promise

The promise is being awaited so the lint rule should not error.

Versions:

  • "eslint": "7.32.0"
  • "eslint-plugin-jest": "25.0.1"
  • Node 14.17.6
@G-Rath
Copy link
Collaborator

G-Rath commented Oct 10, 2021

🤦 I knew I'd forgot a valid situation like that.

Currently we're looking straight up for either a return or an await in the function body, but we should also check (somehow 🤔) if the promise is being awaited as a parameter to a function call that is within the test functions body

@github-actions
Copy link

🎉 This issue has been resolved in version 25.0.3 🎉

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
2 participants