Skip to content

Promises with catch are not considered handled #1058

@puglyfe

Description

@puglyfe

Have you read the Troubleshooting section?

Yes

Plugin version

7.6.1

ESLint version

8.57.0

Node.js version

20.11

Bug description

We have a number of test cases where we expect async queries to fail, and then we either make assertions against the failure, or throw an error to indicate a particular failure mode. However, async queries with .catch() chained are not considered "handled" promises by the plugin.

For example, when testing a custom query:

screen.findByMyCustomQuery('thing-that-doesnt-exist').catch((err) => {
  expect(err.message).toMatch(...)
});

These tests could be re-written to explicitly use async matchers, but this should be a valid pattern as far as I can tell.

Steps to reproduce

add this to the valid entries in the await-async-queries test suite:

...createTestCase(
  (query) => `
    ${query}('foo').catch((error) => {
      expect(error.message).toMatch(/my error message/)
    })
  `
)

Error output/screenshots

No response

ESLint configuration

n/a

Rule(s) affected

await-async-queries, await-async-utils, await-async-events

Anything else?

No response

Do you want to submit a pull request to fix this bug?

Yes

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions