Skip to content

Linting fails as "react-test-renderer" functions are interpreted as functions from "testing-library/react" #888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Sembauke opened this issue Mar 11, 2024 · 2 comments
Labels
awaiting response Waiting for a reply from the OP bug Something isn't working

Comments

@Sembauke
Copy link

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

  1. create a test file of your liking
  2. import react-test-renderer
  3. use findAllByType in a test
  4. run your linter
  5. 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

@Sembauke Sembauke added bug Something isn't working triage Pending to be triaged by a maintainer labels Mar 11, 2024
@Belco90 Belco90 removed the triage Pending to be triaged by a maintainer label Jun 11, 2025
@Belco90
Copy link
Member

Belco90 commented Jun 11, 2025

Hi @Sembauke! I overlooked this issue, sorry about that.

This problem seems related to the Aggressive Reporting. Have you checked the Troubleshooting section to find more about restricting this behavior?

The query mechanism from the Aggressive Reporting is assuming all find(All)By* queries should be treated as Testing Library queries. You can disable this behavior with the custom-queries settings so the plugin stops reporting those queries not coming directly from Testing Library like findAllByType.

@Belco90 Belco90 added the awaiting response Waiting for a reply from the OP label Jun 11, 2025
@Sembauke
Copy link
Author

Thank you for the response Mario, it is greatly appreciated. It has been a while since I tried to solve this issue on my end and my brain decided to get rid of all the context.

But what I read from the "Aggressive Reporting Section":

"Aggressive Reporting", which intends to detect Testing Library utils usages even if they don't come directly from a Testing Library package.

Couldn't this be a cause for a lot of oversight? We might not be directly familiar with the utils we use. Nor the aggressive reporting being a thing itself.

It would be nice if you could bring me up to speed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting response Waiting for a reply from the OP bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants