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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[valid-expect-in-promise] Another false positive #947

Closed
srmagura opened this issue Oct 12, 2021 · 2 comments 路 Fixed by #948
Closed

[valid-expect-in-promise] Another false positive #947

srmagura opened this issue Oct 12, 2021 · 2 comments 路 Fixed by #948
Labels

Comments

@srmagura
Copy link

Hello, it's me again 馃槅. Thank you for the extremely quick fix to #930.

There are other cases where the rule is erroring even though the promise is (indirectly) awaited:

it("throws then resolves", async () => {
  const p = Promise.reject(new Error("myError")).then(undefined, (e) => {
    expect(e).toBeInstanceOf(Error);

    return "handled";
  });

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

it("throws twice", async () => {
  const p = Promise.reject(new Error("myError")).then(undefined, (e) => {
    expect(e).toBeInstanceOf(Error);

    throw new Error("myError2");
  });

  await expect(p).rejects.toThrow("myError2");
});
  2:9  error  This promise should either be returned or awaited to ensure the expects in it's chain are called  jest/valid-expect-in-promise
  12:9  error  This promise should either be returned or awaited to ensure the expects in it's chain are called  jest/valid-expect-in-promise

Repository here

Versions

  • "eslint": "^7.32.0",
  • "eslint-plugin-jest": "^25.0.5"
  • Node 14
@G-Rath
Copy link
Collaborator

G-Rath commented Oct 12, 2021

ha cheers, I actually realised that one while working on #930, but didn't have the time to implement a fix - while generally we cannot support this case because we don't know how a function handles the promise it's being passed, we should make an exception for expect(...).resolves & expect(...).rejects since their "our" functions so do know how they should behave.

SimenB pushed a commit that referenced this issue Oct 14, 2021
#948)

We purposely don't check if the `expect` is `await`ed or returned, as
that is the role of the `valid-expect` rule.

Fixes #947
github-actions bot pushed a commit that referenced this issue Oct 14, 2021
## [25.0.6](v25.0.5...v25.0.6) (2021-10-14)

### Bug Fixes

* **valid-expect-in-promise:** allow `expect.resolve` & `expect.reject` ([#948](#948)) ([71b7e17](71b7e17)), closes [#947](#947)
* **valid-expect-in-promise:** support `await` in arrays ([#949](#949)) ([a62130c](a62130c))
@github-actions
Copy link

馃帀 This issue has been resolved in version 25.0.6 馃帀

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
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants