Skip to content
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

False positive when creating a rendering helper function #731

Open
HenryHall opened this issue Feb 7, 2023 · 1 comment
Open

False positive when creating a rendering helper function #731

HenryHall opened this issue Feb 7, 2023 · 1 comment
Labels
awaiting response Waiting for a reply from the OP question Further information is requested

Comments

@HenryHall
Copy link

Have you read the Troubleshooting section?

Yes

Plugin version

v5.10.0

ESLint version

v8.31.0

Node.js version

v16.8.0

package manager and version

npm 8.19.2

Operating system

Windows 10

Bug description

When creating a helper function that used render internally, I was getting an error (testing-library/render-result-naming-convention) telling me I've picked a poor name and that I should incorrectly destructure the results. Oddly, this only seemed to happen if I imported the function, but used within the same file.

Steps to reproduce

// MyComponent.helper.tsx
import { render } from '@testing-library/react';
import MyComponent from './MyComponent';
export function makeComponentRenderer(config) {
    // do some stuff...
    return function () {
        // do some other stuff...
        return render(<MyComponent />);
    }
}

// When used inside the file, it works without eslint complaining
const config = { /* ... */ };
const someInternal = makeComponentRenderer(config); // OK

// Elsewhere.tsx
import { makeComponentRenderer } from './MyComponent.helper';
const config = { /* ... */ };

// ESLint: `renderMyComponent ` is not a recommended name for `render` returned value. Instead, you should destructure it, or name it using one of: `view`, or `utils`(testing-library/render-result-naming-convention)
const renderMyComponent = makeComponentRenderer(config); // ERROR

Error output/screenshots

No response

ESLint configuration

module.exports = {
    parser: '@typescript-eslint/parser',
    plugins: ['react', 'react-hooks', 'jest-dom', 'testing-library', '@typescript-eslint'],
    parserOptions: {
        project: ['./tsconfig.json'],
        extraFileExtensions: ['.mdx'],
    },
    env: {
        browser: true,
        es2020: true,
        node: true,
    },
    extends: [
        'plugin:react/recommended',
        'plugin:react-hooks/recommended',
        'plugin:react/jsx-runtime',
    ],
    ignorePatterns: ['/dist/*', '/coverage/*', '/public/mockServiceWorker.js'],
    overrides: [
        {
            files: ['./src/**/?(*.)+(spec|test).[jt]s?(x)'],
            extends: ['plugin:jest-dom/recommended', 'plugin:testing-library/react'],
        },
    ],
    settings: {
        react: {
            version: 'detect',
        },
    },
};

Rule(s) affected

testing-library/render-result-naming-convention

Anything else?

No response

Do you want to submit a pull request to fix this bug?

No

@HenryHall HenryHall added bug Something isn't working triage Pending to be triaged by a maintainer labels Feb 7, 2023
@Belco90 Belco90 added question Further information is requested awaiting response Waiting for a reply from the OP and removed bug Something isn't working triage Pending to be triaged by a maintainer labels Feb 8, 2023
@Belco90
Copy link
Member

Belco90 commented Feb 8, 2023

Hi @HenryHall. I'm afraid this is a behaviour related to the Aggressive Reporting feature. In particular, this is coming from custom-renders mechanism.

Please read those docs to know more about how to restrict such behaviour.

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 question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants