Skip to content

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

Open
@Sembauke

Description

@Sembauke

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriagePending 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