Skip to content

False positive for testing-library/await-async-query? #359

Closed
@luhmann

Description

@luhmann

Problem

I upgraded from version 3.10.2 to version 4.1.2 and am now getting errors for await-async-query that I cannot really explain. I read the migration guide to v4 and as far as I can see there is nothing wrong with my code. So I thought I would open this issue.

This is a minimal example of the issue, it popped up all over my codebase

// import from custom-module
import { render, screen } from 'mocks/test-utils'
import userEvent from '@testing-library/user-event'

// I have an object of reusable testdata
const testData = {
  name: 'Theodore Tester',
  email: 'tester@parker.com',
  password: 'extremeSecret',
}

// ... and one of reusable selectors
const selectors = {
  username: () => screen.findByRole('textbox', { name: /username/i }),
  email: () => screen.findByRole('textbox', { name: /e-mail/i }),
  password: () => screen.findByLabelText(/password/i),
}

// which I use in a test
test('when a valid form is submitted, then a success notification is displayed', async () => {
  render(<CreateNewAdminUserPage />)
  userEvent.type(await selectors.username(), testData.name)
  userEvent.type(await selectors.email(), testData.email)
  userEvent.type(await selectors.password(), testData.password)

  // ... more test code and assertions
})

With 4.1.2 I get linting errors for await-async-query on my testdata, but only on some of it:

CleanShot 2021-04-26 at 10 16 18@2x

CleanShot 2021-04-26 at 10 16 52@2x

As you can see in the screenshot there is not linting error on testData.name, but there are on testData.email and testData.password.

What I cannot figure out is:

  1. Why I see the error in the first place. To my understanding I handled the promises as expected in the rule
  2. Why the error is indicated on my testData-object, which does not use promises
  3. Why it is only reported for some of its properties

What I tried

Versions/Config

npm ls eslint-plugin-testing-library
-- eslint-plugin-testing-library@4.1.2

Config

{
      files: ['*.test.{tsx,ts}'],
      extends: ['plugin:jest-dom/recommended', 'plugin:testing-library/react', 'plugin:jest/recommended'],
      plugins: ['jest-dom', 'testing-library', 'jest'],
      rules: {
        'jest/valid-title': ['off'],
        'jest/expect-expect': [
          'error',
          {
            assertFunctionNames: ['expect', 'assert*'],
          },
        ],
        'testing-library/custom-queries': ['off'],
        'testing-library/utils-module': ['off'],
        'testing-library/custom-renders': ['off'],
      },
  },

Thank you for your help!

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingreleased

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions