testing-library / testing-library/eslint-plugin-testing-library
Linting fails as "react-test-renderer" functions are interpreted as functions from "testing-library/react"
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.1k
- Forks
- 168
- Avg merge
- 15h 44m
- Merged PRs (30d)
- 14
Description
Have you read the Troubleshooting section?
Yes
Plugin version
v6.2.0
ESLint version
v8.57.0
Node.js version
v20.5.0
package manager and version
pnpm 8.15.4
Operating system
macOs Sonoma
Bug description
At the moment when I import functions from react-test-renderer and run my linter (eslint . --fix) the testing-library/await-async-queries triggers with a false-positive.
For example trying to use findAllBytype triggers the rule " promise returned from findAllByType query must be handled". But this version has no Promise returned making it redundant, e.g. :
it('has no blockquotes when loggedOut', () => {
const container = rendererCreateWithRedux(
<Intro {...loggedOutProps} />
).root;
expect(container.findAllByType('blockquote').length === 0).toBeTruthy();
expect(container.findAllByType('h1').length === 1).toBeTruthy();
});
The current work around is to disable this rule with an inline comment, but I would like this being resolved in a different way.
Steps to reproduce
- create a test file of your liking
- import
react-test-renderer - use
findAllByTypein a test - run your linter
- observe result
Error output/screenshots
34:22 error promise returned from findAllByType query must be handled testing-library/await-async-queries
ESLint configuration
Details
{
"env": {
"es6": true,
"browser": true,
"mocha": true,
"node": true,
"jest": true
},
"parser": "@babel/eslint-parser",
"parserOptions": {
"babelOptions": {
"presets": ["@babel/preset-react"]
}
},
"root": true,
"extends": [
"eslint:recommended",
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"plugin:import/recommended",
"plugin:jsx-a11y/recommended",
"prettier"
],
"plugins": ["no-only-tests", "filenames-simple"],
"globals": {
"Promise": true,
"window": true,
"$": true,
"ga": true,
"jQuery": true,
"router": true
},
"settings": {
"react": {
"version": "16.4.2"
},
"import/resolver": {
"typescript": true,
"node": true
}
},
"rules": {
"import/no-unresolved": [2, { "commonjs": true }],
"import/named": "error",
"import/no-named-as-default": "off",
"import/no-named-as-default-member": "off",
"import/order": "error",
"import/no-cycle": [2, { "maxDepth": 2 }],
"react/prop-types": "off",
"no-only-tests/no-only-tests": "error",
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"warn",
{
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_",
"caughtErrorsIgnorePattern": "^_"
}
],
"filenames-simple/naming-convention": ["warn"]
},
"overrides": [
{
"files": ["**/*.ts?(x)"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": [
"./client/tsconfig.json",
"./tsconfig.json",
"./api/tsconfig.json",
"./shared/tsconfig.json",
"./tools/ui-components/tsconfig.json",
"./tools/client-plugins/browser-scripts/tsconfig.json",
"./web/tsconfig.json",
"./curriculum-server/tsconfig.json",
"./cypress/tsconfig.json",
"./e2e/tsconfig.json"
]
},
"extends": [
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:import/typescript"
],
"plugins": ["@typescript-eslint"],
"rules": {
"import/no-unresolved": "off",
"import/named": 0,
"@typescript-eslint/naming-convention": "off",
"testing-library/await-async-query": "off"
}
},
{
"files": [
"./tools/ui-components/**/*.test.[jt]s?(x)",
"./client/**/*.test.[jt]s?(x)"
],
"extends": [
"plugin:testing-library/react",
"plugin:jest-dom/recommended"
],
"rules": { "import/named": 2 }
},
{
"files": ["cypress/**/*.js"],
"globals": {
"cy": true,
"Cypress": true
}
},
{
"files": ["e2e/*.ts"],
"rules": {
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-assignment": "off"
}
},
{
"files": ["web/**/*.tsx"],
"extends": ["plugin:react/jsx-runtime"]
},
{
"files": ["**/api-server/**/*", "**/404.*"],
"rules": {
"filenames-simple/naming-convention": "off"
}
},
{
"files": ["**/api/src/**/*.ts"],
"plugins": ["jsdoc"],
"extends": ["plugin:jsdoc/recommended-typescript-error"],
"rules": {
"jsdoc/require-jsdoc": [
"error",
{
"require": {
"ArrowFunctionExpression": true,
"ClassDeclaration": true,
"ClassExpression": true,
"FunctionDeclaration": true,
"FunctionExpression": true,
"MethodDefinition": true
},
"publicOnly": true
}
],
"jsdoc/require-description-complete-sentence": "warn",
"jsdoc/tag-lines": "off"
}
}
]
}
Rule(s) affected
testing-library/await-async-queries
Anything else?
No response
Do you want to submit a pull request to fix this bug?
Yes, but need help
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Use the testing-library/await-async-queries rule as the entry point and reproduce the reported configuration with react-test-renderer and findAllByType. Add coverage for the synchronous query behavior, then verify that findAllByType is not reported while asynchronous queries remain checked.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- eslint, react, typescript
- Domain
- testing, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100