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

no-global-regexp-flag-in-query: TypeError 'value' of undefined #565

Closed
CreativeTechGuy opened this issue Apr 1, 2022 · 3 comments · Fixed by #566
Closed

no-global-regexp-flag-in-query: TypeError 'value' of undefined #565

CreativeTechGuy opened this issue Apr 1, 2022 · 3 comments · Fixed by #566
Labels
bug Something isn't working released

Comments

@CreativeTechGuy
Copy link

CreativeTechGuy commented Apr 1, 2022

Plugin version

5.2.0

ESLint version

8.12.0

Node.js version

16.8.0

npm/yarn version

npm 7.21.0

Operating system

Windows 10

Bug description

I enabled the no-global-regexp-flag-in-query rule and received an error when linting

Steps to reproduce

Create the following test file:

import { screen } from "@testing-library/react";

describe("App", () => {
    test("is rendered", async () => {
        // The line below is the only one that matters here
        await screen.findByText("Hello World", {
            exact: false,
        });
    });
});

Enable the rule and lint

Error output/screenshots

TypeError: Cannot read property 'value' of undefined
Rule: "testing-library/no-global-regexp-flag-in-query"
    at Object.CallExpression (node_modules\eslint-plugin-testing-library\rules\no-global-regexp-flag-in-query.js:76:45)
    at enhancedRuleInstructions.<computed> (node_modules\eslint-plugin-testing-library\create-testing-library-rule\detect-testing-library-utils.js:518:105)    at ruleErrorHandler (node_modules\eslint\lib\linter\linter.js:1114:28)
    at node_modules\eslint\lib\linter\safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (node_modules\eslint\lib\linter\safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (node_modules\eslint\lib\linter\node-event-generator.js:297:26)
    at NodeEventGenerator.applySelectors (node_modules\eslint\lib\linter\node-event-generator.js:326:22)
    at NodeEventGenerator.enterNode (node_modules\eslint\lib\linter\node-event-generator.js:340:14)
    at CodePathAnalyzer.enterNode (node_modules\eslint\lib\linter\code-path-analysis\code-path-analyzer.js:795:23)

ESLint configuration

{
    plugins: ["testing-library"],
    env: {
        es6: true,
        browser: true,
    },
    parser: "@babel/eslint-parser",
    parserOptions: {
        ecmaFeatures: {
            jsx: true,
        },
        sourceType: "module",
        requireConfigFile: false,
    },
    settings: {
        react: {
            pragma: "React",
            version: "detect",
        },
    },
    overrides: [
        {
            files: ["*.test.jsx", "*.test.tsx"],
            rules: {
                "testing-library/no-global-regexp-flag-in-query": "error",
            },
        },
    ],
}

Rule(s) affected

no-global-regexp-flag-in-query

Anything else?

No response

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

No

@CreativeTechGuy CreativeTechGuy added the bug Something isn't working label Apr 1, 2022
@Belco90
Copy link
Member

Belco90 commented Apr 1, 2022

Hey @CreativeTechGuy thanks for reporting! Should be an easy one to fix, let's see if we can tackle this during the weekend.

@AriPerkkio
Copy link
Contributor

This also crashed ~700 times here: #509 (comment). Some more repros available there.

Belco90 added a commit that referenced this issue Apr 4, 2022
#566)

* fix(no-global-regexp-flag-in-query): check if empty name property node

* style: write the valid snippet without an object

Closes #565
@github-actions
Copy link

github-actions bot commented Apr 4, 2022

🎉 This issue has been resolved in version 5.2.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
3 participants