Skip to content

False positive for testing-library/await-async-events when returning using a ternary #887

@jasonblalock

Description

@jasonblalock

Have you read the Troubleshooting section?

Yes

Plugin version

v6.2.0

ESLint version

v8.56.0

Node.js version

20.11.1

package manager and version

yarn 3.2.2

Operating system

macOS Ventura 13.6.4

Bug description

Ternary return of userEvent.type or userEvent.clear is reporting testing-library/await-async-queries, even though the query will get awaited

Steps to reproduce

  1. Go to test file
  2. Add code like
async function changeEmailInput(value) {
	const emailInput = screen.getByRole('textbox', { name: 'Email' });

	return value.length
		? userEvent.type(emailInput, value)
		: userEvent.clear(emailInput);
}
  1. Observe errors on the last two lines

Promise returned from async event method type must be handled eslint testing-library/await-async-events
Promise returned from async event method clear must be handled eslint testing-library/await-async-events

Error output/screenshots

No response

ESLint configuration

{
  ...,
  plugins: [
     ...,
     'eslint-plugin-testing-library'
  ],
  rules: {
    ...,
    'testing-library/await-async-queries': ['error', { eventModule: 'userEvent' }]
  }
}

### Rule(s) affected

testing-library/await-async-queries

### Anything else?

_No response_

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

No

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingreleasedtriagePending to be triaged by a maintainer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions