Closed
Description
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:
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:
- Why I see the error in the first place. To my understanding I handled the promises as expected in the rule
- Why the error is indicated on my
testData
-object, which does not use promises - Why it is only reported for some of its properties
What I tried
- Switch off all aggressive reporting as described here: https://github.com/testing-library/eslint-plugin-testing-library#switching-all-aggressive-reporting-mechanisms-off => no change
- Configuring my custom-utils-module as described here: https://github.com/testing-library/eslint-plugin-testing-library#testing-libraryutils-module => no change
- Switch to
getByRole
-Queries instead offindByRole
=> fixes the issue, but is not really what I want
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!