profile
viewpoint

Ask questions[prefer-explicit-assert] Incomplete expect statement causes TypeError

Plugin version

4.12.2

ESLint version

7.32.0

Node.js version

15.11.0

npm/yarn version

yarn 1.22.10

Operating system

macOS Big Sur, version 11.6

Bug description

Leaving an incomplete expect statement with the prefer-explict-assert rule active breaks the linter.

Steps to reproduce

  • configure the prefer-explicit-assert rule to be active
  • write a basic test which includes expect('something');
  • see that the linter fails with a TypeError

Error output/screenshots

Oops! Something went wrong! :(                                                                                   
                                                                                                                         
ESLint: 7.32.0                                                                                                           
                                                                                                                         
TypeError: Cannot read property 'name' of undefined
Occurred while linting [...]/components/OverrideSummary.test.tsx:1
    at [...]/node_modules/eslint-plugin-testing-library/rules/prefer-explicit-assert.js:124:48
    at Array.forEach (<anonymous>)
    at Object.Program:exit ([...]/node_modules/eslint-pluging-testing-library/rules/prefer-explicit-assert.js:105:31)
    at enhancedRuleInstructions.<computed> ([...]/node_modules/eslint-plugin-testing-library/create-testing-library-rule/detect-testing-library-utils.js:518:105)
    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:293:26)
    at NodeEventGenerator.applySelectors ([...]/node_modules/eslint/lib/linter/node-event-generator.js:322:22)
    at NodeEventGenerator.leaveNode ([...]/node_modules/eslint/lib/linter/node-event-generator.js:345:14)
error Command failed with exit code 2.

ESLint configuration

module.exports = {
  parser: '@typescript-eslint/parser',
  plugins: ['@typescript-eslint', 'jsx-a11y', 'no-only-tests'],
  extends: [
    'react-app',
    'plugin:react/recommended',
    'plugin:@typescript-eslint/recommended',
    'plugin:jsx-a11y/recommended',
    'plugin:prettier/recommended',
    'prettier/@typescript-eslint',
    'prettier/react',
  ],
  parserOptions: {
    ecmaVersion: 6,
    project: ['./tsconfig.json', './cypress/tsconfig.json'],
    sourceType: 'module',
    ecmaFeatures: {
      jsx: true,
    },
  },
  settings: {
    react: {
      version: 'detect',
    },
  },
  rules: {
    '@typescript-eslint/explicit-module-boundary-types': 0,
    'require-await': 0,
    '@typescript-eslint/no-inferrable-types': 1,
  },
  overrides: [
    {
      files: ['cypress/**/*.ts'],
      extends: ['plugin:cypress/recommended'],
      rules: {
        'cypress/no-unnecessary-waiting': 'warn',
      },
    },
    {
      files: ['*.test.ts', '*.test.tsx'],
      extends: ['plugin:testing-library/react', 'plugin:jest-dom/recommended'],
      rules: {
        'no-console': 'off',
        'testing-library/no-debug': 'warn',
        'testing-library/prefer-explicit-assert': ['error', { assertion: 'toBeInTheDocument' }],
        'testing-library/render-result-naming-convention': 'warn',
      },
    },
  ],
};

Rule(s) affected

prefer-explicit-assert

Anything else?

No response

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

Yes, but need help

testing-library/eslint-plugin-testing-library

Answer questions DaJoTo

@Belco90 awesome that you got that patched so quickly. Thank you

useful!

Related questions

No questions were found.
source:https://uonfu.com/
Github User Rank List