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

Should no-conditional-expect prevent Promise catch in tests? #818

Closed
manovotny opened this issue Apr 9, 2021 · 2 comments · Fixed by #819
Closed

Should no-conditional-expect prevent Promise catch in tests? #818

manovotny opened this issue Apr 9, 2021 · 2 comments · Fixed by #819

Comments

@manovotny
Copy link

We recently added no-conditional-expect to our app, and in trying to eliminate try / catch blocks, discovered that the following is possible.

it('foo', async () => {
    await something
        .then(() => throw 'should have thrown an error')
        .catch((error) => {expect(error).toBe('error')})
})

Is that expected or is that a loophole and skirting the intentions of the rule?

@G-Rath
Copy link
Collaborator

G-Rath commented Apr 10, 2021

Yeah probably 😅

tbh I half want to say "no, it only cares about syntax-level conditions" along with an example of how you can easily write a function with a callback, but valid-expect-in-promise looks for promises and hasn't had a lot of complaints about false positives, so we might be able to catch this without too much trouble.

I'll see what I can come up with :)

@github-actions
Copy link

🎉 This issue has been resolved in version 24.3.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
Projects
None yet
2 participants